To add a static method to a subclass in Python, you can use the built-in staticmethod
decorator. Here's an example:
main.py322 chars14 lines
In the above code, we define a Parent
class with a static method foo()
. We then create a Child
subclass of Parent
and add our own static method bar()
using the same syntax.
To call a static method on a class or subclass, you can simply use the class name and the static method name, e.g. Parent.foo()
. Note that static methods don't require an instance of the class to be created before they can be called.
gistlibby LogSnag