0% found this document useful (0 votes)
10 views

Self Self Self Self Self Self: ####Attribute ###Class Variable ### Contructor or Init Method

The document discusses class and object concepts in Python. It contains three examples showing how to define classes with attributes and methods, instantiate objects from classes, and access/modify attributes. In the first example, a class is defined to represent employees with name, department, and company attributes. An object is created and its department is modified before calling its data method. The second example similarly defines a human class with name and age attributes. The third example defines an employee class that takes a code as an argument, sets additional attributes like company and join year, and demonstrates passing arguments to a class.

Uploaded by

Arun Mmohanty
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Self Self Self Self Self Self: ####Attribute ###Class Variable ### Contructor or Init Method

The document discusses class and object concepts in Python. It contains three examples showing how to define classes with attributes and methods, instantiate objects from classes, and access/modify attributes. In the first example, a class is defined to represent employees with name, department, and company attributes. An object is created and its department is modified before calling its data method. The second example similarly defines a human class with name and age attributes. The third example defines an employee class that takes a code as an argument, sets additional attributes like company and join year, and demonstrates passing arguments to a class.

Uploaded by

Arun Mmohanty
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In [8]:

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

Enter your Name: arun


Enter your Dept: it

Employee Name is arun


Employee Dept is it
Company Name is Wipro
Employee code is 101
Locatin is HYD
Join Year is 2019

You might also like