0% found this document useful (0 votes)
22 views9 pages

Unit III File Handling , Classes_Part5

The document discusses key concepts of object-oriented programming, including inheritance, polymorphism, and class structure. It provides examples of class creation, object instantiation, and method implementation in Python. Additionally, it covers the use of the self parameter, modifying and deleting object properties, and the importance of the __init__() method.

Uploaded by

Saraswathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views9 pages

Unit III File Handling , Classes_Part5

The document discusses key concepts of object-oriented programming, including inheritance, polymorphism, and class structure. It provides examples of class creation, object instantiation, and method implementation in Python. Additionally, it covers the use of the self parameter, modifying and deleting object properties, and the importance of the __init__() method.

Uploaded by

Saraswathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Inheritance

 derived class inherits properties from base class


 derived class
 based class
Polymorphism
 implementing same method in different context.
 method with same name implementing different way
+
For Instance
 Institution:
 Faculty Details
 Students Details
 Non Faculty Details
 Other Details
 Personal Details : : Name , DOB, Address
 Faculty Details : Designation, salary, Attendence
 Students Details : Progress, Attendence
 Non Faculty Details : Designation, salary, Attendence
class Point:
def init (self,a=0,b=0):
self.x=a
self.y=b

def str (self):


return "(%d,%d)"%(self.x, self.y)

def add (self, p2):


p3=Point()
p3.x=self.x+p2.x
p3.y=self.y+p2.y
return p3
p1=Point(10,20)
p2=Point()
print("P1 is:",p1)
print("P2 is:",p2)
p4=p1+p2
print("Sum is:",p4)
Key points to remember
 Create a Class : class MyClass:
 Create Object : p1 = MyClass()
 The __init__() :
 the built-in __init__() function every class
 which is always executed when the class is being initiated
 We use to assign values to object properties
 Object Methods : p1.myfunc()
 The self Parameter :
 reference to the current instance of the class
 Modify Object Properties : p1.age = 40

 Delete Object Properties : del p1.age


 delete properties on objects by using the del keyword
 Delete Objects : del p1
 delete objects by using the del keyword
 The pass Statement :
 Class cannot be empty class Person:
 For some reason have a class definition with no content pass
Self Parameter
class Person:
def __init__(mysillyobject, name, age):
mysillyobject.name = name
mysillyobject.age = age

def myfunc(abc):
print("Hello my name is " + abc.name)

p1 = Person("John", 36)
p1.myfunc()
Class
 data
 functions
student
roll_no
name

write
read

 syntax:
 object.name=class_name()
Class class Student:
Student_RollNo=10
Student_Name=“John”
 data
 functions
student
roll_no
name

write
read

functions
 syntax:
 object.name=class_name()
class Dog:

# A simple class
# attribute
attr1 = "mammal"
attr2 = "dog"

# A sample method
def fun(self):
print("I'm a", self.attr1)
print("I'm a", self.attr2)

# Driver code
# Object instantiation
Rodger = Dog()

# Accessing class attributes


# and method through objects
print(Rodger.attr1)
Rodger.fun()

You might also like