Self Self Self Self Self Self: ####Init Method or Constructor
Self Self Self Self Self Self: ####Init Method or Constructor
class car:
def model(self):
print(f"we have 10 {self.__car_model} model in store")
print(f"we have 10 {self.__car_m} model in store")
In [2]:
class car:
#car_model=' ' ####these are know as attributes or local variable or
#car_m=' ' ###opject orients varaiable
def __init__(self, md, m): ####init method or constructor
self.car_model = md
self.car_m = m
def model(self):
print(f"we have 10 {self.car_model} model in store")
print(f"we have 10 {self.car_m} model in store")
a=car('muriti', 'hundai')
a.model()
In [2]:
class car:
def model(self):
print(f"we have 10 model in store")
b=car()
b.model()
class car:
def __init__(self, md): ####init method or constructor
self.car_model = md
def model(self):
print(f"we have 10 {self.car_model} model in store")
a=car('muriti')
a.model()
In [17]:
class emp:
cc='IBM' ####attribute ###class variable
def __init__(self,name,dept): ### contructor or init method
self.n=name
self.d=dept
def data(self):
print(f'Employee Name is {self.n}') ####contructor attaributes
print(f'Employee Dept is {self.d}')
print(f'Company Name is {emp.cc}') ### class variable
x=emp('Arun', 'IT')
x.data()
In [19]:
n='arun'
d='dept'
c='IBM'
def data(name,dept):
print(f'Employee Name is {name}')
print(f'Employee Dept is {dept}')
print(f'Company Name is {c}')
data(n,d)
class emp:
cc='IBM' ###class variable
def __init__(self,name,dept): ### contructor or init method
self.n=name
self.d=dept
def data(self):
print(f'Employee Name is {self.n}') ####contructor attaributes
print(f'Employee Dept is {self.d}')
print(f'Company Name is {emp.cc}') ### class variable
x=emp('Arun', 'IT')
x.dept='HR'
print(x.dept)
x.data()
HR
Employee Name is Arun
Employee Dept is IT
Company Name is IBM
In [ ]: