Python has been an object-oriented language since it existed. Because of this, creating and using classes and objects are downright easy. This chapter helps you become an expert in using Python's object-oriented programming support.
If you do not have any previous experience with object-oriented (OO) programming, you may want to consult an introductory course on it or at least a tutorial of some sort so that you have a grasp of the basic concepts.
However, here is small introduction of Object-Oriented Programming (OOP) to bring you at speed :
To create a class, use the keyword class :
To understand the meaning of classes we have to understand the built-in __init__() function. All classes have a function called __init__(), which is always executed when the class is being initiated. Use the __init__() function to assign values to object properties, or other operations that are necessary to do when the object is being created:
Note : The __init__() function is called automatically every time the class is being used to create a new object.
Objects can also contain methods. Methods in objects are functions that belongs to the object.
Note : The self parameter is a reference to the class instance itself, and is used to access variables that belongs to the class.
You can modify properties on objects like this:
obj.age = 24 or you can delete properties on objects by using the del keyword, like this :
del obj.age or,
del obj .
Currently we improved our website User Interface and other contents. Our next update is adding video tutorials on this site so, We create a new YouTube channel, our YouTube channel name is CodeX.
We need some time for make video tutorials (CodeX) so, stay with us and keep supporting and you know already we make a Collaboration with HackIsOn YouTube channel long time ago So, please Subscribe Our Channels