self represents the instance of the class. By using the “self” keyword we can access the attributes and methods of the class in python. It binds the attributes with the given arguments.
The reason you need to use self. is because Python does not use the @ syntax to refer to instance attributes. Python decided to do methods in a way that makes the instance to which the method belongs be passed automatically, but not received automatically: the first parameter of methods is the instance the method is called on
Model is audi a4 color is blue Model is ferrari 488 color is green
Self is a convention and not a real python keyword
self is parameter in function and user can use another parameter name in place of it.But it is advisable to use self because it increase the readability of code.
we have used another parameter name in place of self
- Inner Class in Python
- Inheritance in Python Inner Class
- Wrapper Class in Python
- First Class functions in Python
- Class as decorator in python
- Class or Static Variables in Python
- Python Bokeh - Colors Class
- Changing Class Members in Python
- String Template Class in Python
- Extend Class Method in Python
- How to Get a List of Class Attributes in Python?
- How to create an empty class in Python?
- Class and Instance Attributes in Python
- Print objects of a class in Python
- Matplotlib.patches.Circle class in Python
- Matplotlib.ticker.PercentFormatter class in Python
- Matplotlib.patches.ArrowStyle class in Python
- Matplotlib.patches.ConnectionPatch class in Python
- Matplotlib.colors.Normalize class in Python
- Matplotlib.ticker.MaxNLocator Class in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : sudhansan5