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.