2. Class Methods
Class methods work with class variables and are accessible using the name rather than its object.
@classmethod decorator is used to create class methods. cls is used to refer to the class just like self is used to refer to the object of the class.
Class methods work with class variables and are accessible using the name rather than its object.
@classmethod decorator is used to create class methods. cls is used to refer to the class just like self is used to refer to the object of the class.
3. Static Methods
usually limited to class. They have no direct relation to class or instance variables. They are used as utility functions inside the class or when we don't want the inherited classes.
@staticmethod decorator is used to define static methods.
usually limited to class. They have no direct relation to class or instance variables. They are used as utility functions inside the class or when we don't want the inherited classes.
@staticmethod decorator is used to define static methods.
Here is the source code all the examples we used in this thread.
Star the repo if you like the content.
github.com
Star the repo if you like the content.
github.com
Follow me @itsafiz for more amazing content.
Like and RT the first tweet in this thread to share with your friends.
Like and RT the first tweet in this thread to share with your friends.
Loading suggestions...