Unit 3 Python Notes
Unit 3 Python Notes
important(files,classes)
unit3
oop
|--->groups related variables and functions into data sturctures called objects
>encapsulation
>polymorphism
>inheritance
self parameter is a reference to the current instance of the class and its used to
across the variable belongs to the class
the name 'self' can be replaced with any other name but has to be the first
parameter in any function in a class
class python:
def __init__(self,section):
self.section=section
c1=python("A")
print(c1)
class python:
def __init__(self,section):
self.section=section
def __str__(self):
return f"{self.section}"
c1=python("A")
print(c1)
class python:
def __init__(self,section,rollno):
self.section=section
self.rollno=rollno
def first(self):
print("my class is "+ self.section)
A1=python("A",66)
A1.first()
class product:
def __init__(self,name,price,discountpercent):
self.name=name
self.price=price
self.discountpercent=discountpercent
def getdiscountamount(self):
return self.price+self.discountpercent/100
def getdiscountamount(self):
return self.price _self.discount amount()
):