#25 - (OOP) Instance method, Class method & Static method in Python

preview_player
Показать описание
Learn about instance method, class method and static method in python class. Instance method is the most common method in python class and is also called as regular method. Instance method takes object i.e. 'self' as it's first parameter. Inside an instance method, we can access class & instance variables with self attribute.
Class method takes the class i.e. 'cls' as it's first parameter. We can use different name as well, but the convention is to use 'cls' to define a class parameter. Inside a class method, we can access class variables with class attribute. We have to use @classmethod decorator to define a class method.
Static method does not need to have an object or class as it's first parameter. We only include them in class because they have a logical connection. For the static method, there should be no use of class or instance variable.

Рекомендации по теме
Комментарии
Автор

I'm Brazilian and I'm learning python, and even with the language difficulty I managed to learn from your video what I didn't learn from the Brazilian videos! Thanks.

KaiqueGamesPlay
Автор

Such a short video...But the concept was so clearly explained...On the other hand there are some really long ones with no clear message... Thank you.

charltondsouza
Автор

Thanks for the video. Can you please let me know why do we write self.first_name = first_name? What is its significance?

dhananjaymalhotra
Автор

This is explain very well, thank you!

thebeastmaster
Автор

Very well explained in a simple and clean way, thank you!

roopagl
Автор

nice tutorial, thanks... got thinking, what if instead of creating a class for change_company(new_name), you add "new_name" as a parameter in the instance method? so it would be Employee(self, first_name, last_name, company).. I guess it would be possible to do so? and how the class method is better than that? thanks!

horacio_llegolamiel
Автор

Thanks for the video!! It really helped me understand these concepts better

ABC-qpcd
Автор

Nice video Thank you for the explanation!

victorgomez