• Post author:
  • Post category:Python
  • Reading time:1 mins read

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:

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)


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

See also:

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.in and orclqa.com a question and answer forum for developers.

This Post Has 3 Comments

  1. Nikita

    What's the need of creating empty class btw?

    1. Vinish Kapoor

      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.

  2. Netster

    I’m learning Python right this moment. Thank you for the post

Comments are closed.