Creating a class instance
Last updated: Feb 11, 2025
You can use classes to hold class (or shared) attributes or to create class instances. To create an instance of a class, you call the class as if it were a function. For example, consider the following class:
class MyClass: pass
Here, the
statement is used because a statement
is required to complete the class, but no action is required programmatically. pass
The following statement creates an instance of the class
:MyClass
x = MyClass()
Was the topic helpful?
0/1000