Object Creation in Python

Previous
Next

Creating object in main():

  • Application execution starts from static context(main).
  • We can access non static members using object address.
  • We create object(take permission) in static context(main)
class Test:
    def __init__(self):
        print("Constructor")
        return
    
    def main():
        Test() #access constructor
        return

Test.main()

Constructor executes every time when we create the object.

class Test:
    def __init__(self):
        print("Constructor")
        return
    
    def main():
        for i in range(10):
            Test()
        return

Test.main()
Previous
Next

Add Comment

Courses Enquiry Form