Class instantiation uses function notation. : Class instantiation : Class PYTHON examples


PYTHON examples » Class » Class instantiation »

 

Class instantiation uses function notation.





#Just pretend that the class object is a 
#parameterless function that returns a new instance of the class.

class MyClass:
    "A simple example class"
    i = 12345
    def f(self):
        return 'hello world'


x = MyClass()

# creates a new instance of the class and assigns this object to the local variable x.



           
       



    Related Scripts with Example Source Code in same category :

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Class
» Class instantiation