Showing posts with label static variable. Show all posts
Showing posts with label static variable. Show all posts

Jun 19, 2013

Static member in Python

Python has different syntax from most common OOP languages like C++ or Java. When declaring variables, the name is not followed by a type identifier or scope modifier. For creating a static member of a class, simply write it inside the class outside of the scope of member functions. To declare a variable belonging to instance, simply add self. prefix.
class Some_class(Name_of_super_class): static_field = 0.0 __init__() : self.variable_belonging_to_instance = 1.0 print("object of Some_class instantiated") @staticmethod def static_method() : print("static method called") static_return = 1.0 return static_return