If you are facing any issue in playing video please use Firefox browser.
Constructor and Destructor in Python
In this lecture we will see that -
What is Constructer and Destructor ?
What is the life cycle of object ?
How to implement class and objects in Python ?
Constructors in Python
Class functions that begins with double underscore (__) are called special functions as their special meaning.
_init_(self) function - this special function gets called whenever a new object of the class is instantiated.
Life cycle of object in Python
Step 1 : Definition
Python defines its classes with keyword 'class' which is defined in Python interpretor.
Step 2 : Initialization
When an instance of the class is created, _init_ method defined in the class is called. It initializes the attributes for newly created class instance. A namespace is also allocated for object's instance variables.
Step 3 : Access and Manipulation
Methods defined in a class can be used for accessing and modifying the state of an object. This are accessors and manipulators respectively. A class instance is used to call this methods.
Step 4 : Destruction
Every object that's created needs to be destroyed. This is done with Python garbage collection (that is reference counting).
"To get Student Information..."
print ("Value set...")
print("Id : ",self.id)
print("Name : ",self.name)
Id : 1
Name : Nirmal
Email : email@example.com
To get Student Information...
Have a friend to whom you would want to share this course?