Join 36000+ teachers and students using TTIO.
It may be helpful to think of a class as a factory for making objects. The class itself isn’t an instance of a point, but it contains the machinery to make point instances. Every time we call the constructor, we’re asking the factory to make us a new object. As the object comes off the production line, its initialization method is executed to get the object properly set up with its factory default settings.
The combined process of “make me a new object” and “get its settings initialized to the factory default settings” is called instantiation. Instantiating a class is creating a copy of the class which inherits all class variables and methods. Instantiating a class in Python is simple. To instantiate a class, we simply call the class as if it were a function, passing the arguments that the __init__ method defines.
Putting it altogether - creating instances of classes that interact in a whole system. Watch the following video and follow along to create your own class based library system.
Below is a demonstration of how we can use the class named MyClass to create objects:
Example: Create an object named p1, and print the value of x:
p1 = MyClass()
print(p1.x)
www.teachyourselfpython.com