How can I make an instance of a class?


#1

Question

How can I make an instance of a class?

Answer

In Python we can create an object from a class by writing the basic structure: my_object = ClassName("parameters_if_any").
Be sure to put this outside your class, otherwise it will be considered part of the class code block and will not execute when you press Run. It should have no indentation before it.


FAQ: Learn Python - Classes - Class basics FAQ: Learn Python - Classes - Create an instance of a class