FINAL PYTHON
FINAL PYTHON
r: open an existing file for a read operation. Data Abstraction is the process of hiding the internal implementation details and
showing only the essential features of an object.
w: open an existing file for a write operation.
Data hiding.
a: open an existing file for append operation.
Data hiding is a software development technique specifically used in Object-Oriented
r+: To read and write data into the file. Programming (OOP) to hide internal object details (data members).
Identity Operators :
Identity operators are used to check whether both operands are same or not.
Python provides ‘is’ and ‘is not’ operators which are called identity operators.
Identity Operators are used to check if two values are located on the same part
of the memory or Not.
Append Mode
This mode opens the file to add new data at the end without deleting the
existing content. If the file does not exist, it creates New File.
Example:
f = open("data.txt", "a")
Example: In Python, strings are immutable, which means you cannot change characters in
the string directly after it's created.
numbers = [1, 2, 3, 4]
Example:
print(numbers) Output: [1, 2, 3, 4]
str = 'rutik'
Set –
str2 = "sakshi"
A set is an unordered collection of unique elements. It does not allow
duplicate values. print(str) Output : rutik
Output: {'apple', 'banana', 'cherry'} A tuple is similar to a list but its immutable. Once a tuple is created, its
elements cannot be modified.
Dictionaries-
Example:
A python dictionary is a collection of key and value pairs separated by a colon
(:) , enclosed in curly braces {}. coordinates = (10, 20, 30)
Method overloading Method Overriding is the ability of a class to change the implementation of a
method provided by one of its base class.
Method overloading is the ability to define the method with the same name
but with a different number of arguments and data types. To override a method in the base class, we must define a new method with same
name and same parameters in the derived class.
Method overloading is a concept in which a method in a class performs
method overriding a class may "copy" another class, avoiding duplicated code, and
operations according to the parameters passed to it.
at the same time enhance or customize.
this ability one method can perform different tasks, depending on the number
Example -
of arguments or the types of the arguments given.
class Car(Vehicle):
Example-
def start_engine(self):
class Demo:
print("Starting the car's engine... Vroom Vroom!")
def method(self, a):
print(a)
class Motorcycle(Vehicle):
obj= Demo( )
def start_engine(self):
obj.method(50)
print("Starting the motorcycle's engine... Vroom Vroom!")
obj.method('Meenakshi')
obj.method(100.2) OUTPUT-
50
Meenakshi
100.2
Explain inheritance in Python with example.
In Python Inheritance is a feature of Object-Oriented Programming (OOP) that
allows a class to inherit attributes and methods from another class.
Inheritance promotes the reuse of code by allowing a new class to inherit properties
and behaviors from an existing class.
In inheritance, the child class acquires the properties and can access all the data
members and functions defined in the parent class.
Syntax:
class A:
# properties of class A
class B(A):
class Animal:
def sound(self):
print("animal sound")
class Dog(Animal):
def sound(self):
print("Bark")
# Creating objects
animal = Animal()
dog = Dog()
# Calling methods
animal.sound()
dog.sound()