Python is an object oriented programming language.
Major principles of object-oriented programming system are given below.
Class :-
The class can be defined as a collection of objects. It is a logical entity that has some specific attributes and methods. For example: if you have an employee class, then it should contain an attribute and method, i.e. an email id, name, age, salary, etc.
The class statement creates a new class definition. The name of the class is created by the keyword class followed by a colon
A class is a blueprint for the object.
Object :-
The object is an entity that has state and behavior. It may be any real-world object like the mouse, keyboard, chair, table, pen, etc.
When we define a class, it needs to create an object to allocate the memory.
Example
we have created the class named car, and it has two attributes modelname and year. We have created a c1 object to access the class attribute. The c1 object will allocate memory for these values
Example
Example
__init()__
The __init__() function is called automatically every time the class is being used to create a new object.
The first method __init__() is a special method, which is called class constructor or initialization method that Python calls when you create a new instance of this class.
Here the self is used as a reference variable, which refers to the current class object. It is always the first argument in the function definition. However, using self is optional in the function call.
self parameter :- The self-parameter refers to the current instance of the class and accesses the class variables. We can use anything instead of self, but it must be the first parameter of any function which belongs to the class.
Delete the Object :-
We can delete the properties of the object or object itself by using the del keyword.
Trending Tutorials