How to define an empty class in python

Last updated 3 months, 1 week ago | 141 views 75     5

Tags:- Python

Python | Create an empty class

In python, it required adding a pass statement to define an empty class. The pass is a special statement in python that does nothing. It just works as a dummy statement.

 

This is an example of how to define an empty class in python. 

class A:
    pass

# define object
obj = A()
print(obj)

# set an attribute of the object for the empty class
obj.title = 'Empty Class'
print(obj.title)

Output for the above code

>>> 
===================== RESTART: E:\py\empty_class.py =====================
<__main__.A object at 0x000002B88AEA4788>
Empty Class