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

Поделиться
HTML-код
  • Опубликовано: 21 сен 2024
  • 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.
    Facebook: / techvitals

Комментарии • 23

  • @KaiqueGamesPlay
    @KaiqueGamesPlay 2 года назад +3

    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.

    • @TechVitals
      @TechVitals  2 года назад

      This means a lot to me. Thanks for the acknowledgment.

    • @KaiqueGamesPlay
      @KaiqueGamesPlay 2 года назад

      @@TechVitals :)

  • @charltondsouza9140
    @charltondsouza9140 2 года назад +1

    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.

  • @MuhammadTanveer-t4s
    @MuhammadTanveer-t4s Год назад

    Keep it up, dude.

  • @shafiulamin4128
    @shafiulamin4128 3 месяца назад

    Nice video

  • @roopagl2719
    @roopagl2719 2 года назад

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

  • @salmanmalik5029
    @salmanmalik5029 2 года назад

    Good explanation....

  • @ABC-qp4cd
    @ABC-qp4cd 2 года назад

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

  • @dhananjaymalhotra7854
    @dhananjaymalhotra7854 2 года назад +1

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

    • @TechVitals
      @TechVitals  2 года назад

      first_name is a parameter that holds the value sent through the object, and self.first_name is the instance variable that actually stores the value for the object. Therefore, when we create an object for a class, we send the value using the first_name parameter and then inside __init__(...), we save the value for that object using self.first_name. NOTE: self refers to the object of the class, so self.first_name means the first_name of that object for a class. Hope this helps.

  • @thebeastmaster2710
    @thebeastmaster2710 Год назад

    This is explain very well, thank you!

  • @victorgomez335
    @victorgomez335 2 года назад

    Nice video Thank you for the explanation!

  • @MilitaryTest
    @MilitaryTest 2 года назад

    Thanks for this video!

  • @horacio_llegolamiel3758
    @horacio_llegolamiel3758 3 года назад

    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!

    • @roopagl2719
      @roopagl2719 2 года назад +1

      yes, its possible. But use case for class attribute "company" is when a company wants to keep record of all of its employees. So in that case we need not pass company every time we create an employee record, as it remains same. We would use class method change_company() only when company gets a new name. Hope this helps

  • @rahulketech-h8e
    @rahulketech-h8e 3 года назад

    keep it up...

  • @rahulketech-h8e
    @rahulketech-h8e 3 года назад

    nice