A class is a user-defined blueprint or prototype from which objects are created. Class can be considered as a user-defined data type. Generally, a class contains data members known as attributes of the class and member functions that are used to modify the attributes of the class. But have you ever wondered how to define an empty class i.e a class without members and member functions?
In Python, if we write something like the following, it would raise a
File "gfg.py", line 5 ^ SyntaxError: unexpected EOF while parsing
In Python, to write an empty class
pass statement is used.
pass is a special statement in Python that does nothing. It only works as a dummy statement. However, objects of an empty class can also be created.
<__main__.Geeks object at 0x02B4A340>
Python also allows us to set the attributes of an object of an empty class. We can also set different attributes for different objects. See the following example for better understanding.
obj1 Details: Name: Nikhil Office: GeeksforGeeks obj2 Details: Name: Abhinav Office: GeeksforGeeks Phone: 1234567889
Traceback (most recent call last): File "gfg.py", line 34, in
print("Phone:", obj1.phone) AttributeError: 'Employee' object has no attribute 'phone'
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Create an empty text file with current date as its name
- Create an empty file using Python
- Wand - Create empty image with background
- wxPython - Create empty window
- How to create an empty DataFrame and append rows & columns to it in Pandas?
- Create empty dataframe in Pandas
- How to create an empty and a full NumPy array?
- Python program to create Bankaccount class with deposit, withdraw function
- Python Tkinter | Create different type of lines using Canvas class
- Python Tkinter | Create different shapes using Canvas class
- How to create a list of object in Python class
- wxPython - Create Radio Button using Create() function
- wxPython - Create Static Box using Create() method
- How to write an empty function in Python - pass statement?
- numpy.empty() in Python
- Python - Check if a list is empty or not
- Python | Remove empty tuples from a list
- Python | Remove and print every third from list until it becomes empty
- Python | First Non-Empty String in list
- Python program to check if string is empty or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.