Self Self Self Self Self Self: ####Attribute ###Class Variable ### Contructor or Init Method
Self Self Self Self Self Self: ####Attribute ###Class Variable ### Contructor or Init Method
class emp:
cc='IBM' ####attribute ###class variable
def __init__(self,name,dept): ### contructor or init method
self.name=name
self.dept=dept
def data(self):
print(f'Employee Name is {self.name}') ####contructor attaributes
print(f'Employee Dept is {self.dept}')
print(f'Company Name is {emp.cc}') ### class variable
x=emp('Arun', 'IT')
x.dept='HR' ###modify the variable
print(x.dept)
x.data()
HR
Employee Name is Arun
Employee Dept is HR
Company Name is IBM
In [10]:
class human:
def __init__(self, name, age):
self.name=name
self.age=age
def h_data(self):
print(f'Name is {self.name}\nAge is {self.age}')
obj1=human('arun', '30')
obj1.age=19
print(obj1.age)
obj1.h_data()
19
Name is arun
Age is 19
In [22]:
class emp:
loc='HYD' ####attribute ###class variable
def __init__(self, emp_c): ### contructor or init method ### pass a arguments
name=input("Enter your Name: ") ####taking input from keybaord
dept=input("Enter your Dept: ")
self.name=name
self.dept=dept
self.comp='Wipro' ##attributes from constructor ##variable from constructor
self.emp_c=emp_c ###pass arguments as a function
self.j_year=2019
def data(self):
print(f'\nEmployee Name is {self.name}') ####contructor attaributes
print(f'Employee Dept is {self.dept}')
print(f'Company Name is {self.comp}') ### class variable
print(f'Employee code is {self.emp_c}')
print(f'Locatin is {emp.loc}') ### call class variable indside function
print(f'Join Year is {self.j_year}')
x=emp(101)
x.data()