0% found this document useful (0 votes)
57 views3 pages

Self Self Self Self Self Self: ####Init Method or Constructor

The document discusses class definitions and object instantiation in Python. It defines Car and Employee classes with attributes and methods. The Car class is defined with model and manufacturer attributes and a model method to print them. Objects are instantiated from the Car class and the model method is called. The Employee class defines name, department, and company attributes in the __init__ method and a data method to print them. An object is instantiated from the Employee class and its data method is called. Class and instance attributes and methods are demonstrated.

Uploaded by

Arun Mmohanty
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)
57 views3 pages

Self Self Self Self Self Self: ####Init Method or Constructor

The document discusses class definitions and object instantiation in Python. It defines Car and Employee classes with attributes and methods. The Car class is defined with model and manufacturer attributes and a model method to print them. Objects are instantiated from the Car class and the model method is called. The Employee class defines name, department, and company attributes in the __init__ method and a data method to print them. An object is instantiated from the Employee class and its data method is called. Class and instance attributes and methods are demonstrated.

Uploaded by

Arun Mmohanty
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/ 3

In [18]:

class car:

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")

obj1 = car('hundai', 'muruti')


obj1.model()
print('-'*56)
car('hundai', 'muruti').model()

we have 10 hundai model in store


we have 10 muruti model in store
--------------------------------------------------------
we have 10 hundai model in store
we have 10 muruti 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()

we have 10 muriti model in store


we have 10 hundai model in store

In [2]:

class car:

def model(self):
print(f"we have 10 model in store")

b=car()
b.model()

we have 10 model in store


In [5]:

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()

we have 10 muriti model in store

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()

Employee Name is Arun


Employee Dept is IT
Company Name is IBM

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)

Employee Name is arun


Employee Dept is dept
Company Name is IBM
In [2]:

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 [ ]:

You might also like