Press "Enter" to skip to content

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:

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Be First to Comment

    Leave a Reply

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