Static Members in Python

Previous
Next

Static members:

  • Free accessible members can be defined as static.
  • These are also called “class” members.

Note: Generally, we access the variables and functions directly after definition.

a=10
def test():
    print("test")
    return

print("a val :",a)
test()
  • In Object Oriented application, variables and methods must be defined inside the class.
  • “class” is a keyword.
  • Defining variable and method inside the class called “static members”
  • We need to access static members using identity of class.
class Test:
    a=10 # static
    def fun():
        print("static fun")
        return

print("a val :",Test.a)
Test.fun()
  • Python application should starts with main() method.
  • Main() is static always as it is starting point of application.
  • Main() method belongs to a single program(class) by which application starts.
class Test:
    a=10 

    def fun():
        print("static fun")
        return

    def main():
        print("starts @ main")
        print("a val :", Test.a)
        Test.fun()
        return

Test.main()
Previous
Next

Add Comment

Courses Enquiry Form