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

Class

The document provides an example of a Python class named 'Person' with attributes for name, gender, and profession, along with methods to display this information and simulate work behavior. It explains the purpose of the __init__ method for initializing object attributes and emphasizes the importance of the 'self' parameter. An instance of the class is created and methods are called to demonstrate its functionality.

Uploaded by

Vathana D
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Class

The document provides an example of a Python class named 'Person' with attributes for name, gender, and profession, along with methods to display this information and simulate work behavior. It explains the purpose of the __init__ method for initializing object attributes and emphasizes the importance of the 'self' parameter. An instance of the class is created and methods are called to demonstrate its functionality.

Uploaded by

Vathana D
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Example : class

class Person:
def __init__(self, name, gender, profession):
[Link] = name
[Link] = gender
[Link] = profession# data members (instance variables)

def show(self):
print('Name:', [Link], 'Gender:', [Link], 'Profession:', [Link]) #
Behavior (instance methods)
def work(self):
print([Link], 'working as a', [Link]) #Behavior (instance methods)

Arun = Person('Arun', 'Male', 'Software Engineer') # create object of a class

Output
[Link]() # call methods
[Link]() Name: Arun Gender: Male Profession:
Software Engineer
Arun working as a Software Engineer
__init__ method, self
• The python __init__ method is declared within a class
and is used to initialize the attributes of an object as
soon as the object is formed.
• While giving the definition for an __init__(self)
method, a default parameter, named 'self' is always
passed in its argument.
• This self represents the object of the class itself.

You might also like