in

How to Create Empty Class in Python?

In Python, you can create an empty class by using the pass command after the definition of the class object, because one line of code is compulsory for creating a class. Pass command in Python is a null statement; it does nothing when executes. The following is an example of an empty class object in Python.

Create an Empty Class in Python Example

In the below Python program, we will create an empty class customer. However, we can still define the objects outside of the customer class and would be able to use in our Python program.

class customer:
    pass

customer1 = customer()

customer1.first_name = 'John'
customer1.last_name = 'Greenberg'

customer2 = customer()

customer2.first_name = 'Nancy'
customer2.last_name = 'Lorrentz'
#customer 2 is also having a phone number
customer2.phone = '893-039-239'

print('Customer 1:', customer1.first_name, customer1.last_name)
print('Customer 2:', customer2.first_name, customer2.last_name, 'Phone No.', customer2.phone)

Output

Customer 1: John Greenberg
Customer 2: Nancy Lorrentz Phone No. 893-039-239

See also:

Written by Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.org and orclqa.com a question and answer forum for developers. You can connect with me on Facebook and Twitter.

3 Comments

Leave a Reply
    • There are several advantages of empty class in Python.

      The one you can see in the above example, that the customer class is not static class, it is a kind of a dynamic class now. You can add any attributes to it.

Leave a Reply

Your email address will not be published. Required fields are marked *