UNIT-V Python
UNIT-V Python
=============================================
UNIT-V Object Oriented Programming in Python
=============================================
Example:
class Student:
def getdata(self):
self.rollno=1010;
self.name="Dennis";
self.marks=98.99;
def display(self):
print("Student Roll No:",self.rollno);
print("Student Name:",self.name);
print("Student Marks:",self.marks);
s1=Student();
• constructor:
- Constructor is a special method of the class.
- In python __init__() method is called constructor.
- Syntax:
def __init__(self):
#body of constructor
• Class Attributes:
============================
Inheritance
============================
- The process of creating new class by using the concept of old class
is known as Inheritance.
- Syntax:
class A:
#properties of class A
class B(A):
#properties of class B
#Inherited properties of class A
✓ Single Inheritance:-
- To create new class from only one base class is known as Single
Inheritance.
✓ Composition Classes:
def send_email(self,msg):
print("Sending {} from Yahoo".format(msg));
class Email:
provider=Gmail();
def set_provider(self,p):
self.provider=p;
def send_email(self,msg):
self.provider.send_email(msg);
client1=Email();
client1.send_email("Hello");
client1.set_provider(Yahoo());
client1.send_email("Hello");
VJTech Academy…