To create a static function in Python, you can use the @staticmethod
decorator. A static method does not require an instance of the class to be called and can be called directly from the class. Here is an example:
main.py370 chars12 lines
As you can see in the example above, the @staticmethod
decorator is used to define a static method my_static_method()
inside the MyClass
class. The static method can be called directly from the class MyClass
without the need for an instance of the class. If an instance of the class is created, the static method can still be called from the instance as well.
gistlibby LogSnag