Static member in Python

Jan 19, 2016

For creating a static field of a class, write it inside the class outside of the scope of any member functions. To declare a variable belonging to instance, add self. prefix. To make a function static, add the @staticmethod decorator.

class Some_class(Name_of_super_class):

    static_field = 0.0

        self.variable_belonging_to_instance = 1.0
        print("object of Some_class instantiated")

    def static_method():
        print("static method called")
        static_return = 1.0
        return static_return