In this tutorial, I will explain how to create and use an empty constructor in Python. Recently, while working on a project for a client in New York, I encountered a situation where I needed to initialize a class without setting any initial values. This scenario is common when you want to create objects dynamically and set their attributes later. This tutorial will help you understand how to implement an empty constructor and its different methods with examples.
What is a Constructor in Python?
A constructor is a special method in Python that is automatically called when an object of a class is created. Constructors are typically used to initialize the instance variables of a class. In Python, the __init__ method serves as the constructor.
The Need for an Empty Constructor in Python
An empty constructor in Python can be useful in scenarios where you want to create an object without initializing it immediately. This can be particularly handy in large applications where object attributes are set based on various conditions or inputs.
Create an Empty Constructor in Python
In Python, you can create an empty constructor by defining the __init__ method without any parameters (except self) and without any initialization code.
Here’s an example:
class Employee:
def __init__(self):
pass
# Creating an instance of Employee
emp = Employee()In this example, the Employee class has an empty constructor. The pass statement is used as a placeholder to indicate that no action is taken.
Check out Constructor Overloading in Python
Set Attributes After Object Creation
Even though the constructor is empty, you can still set attributes for the object after it is created. Here’s how you can do it:
class Employee:
def __init__(self):
pass
# Creating an instance of Employee
emp = Employee()
# Setting attributes
emp.name = "John Doe"
emp.position = "Software Engineer"
emp.location = "San Francisco"
print(f"Employee Name: {emp.name}")
print(f"Position: {emp.position}")
print(f"Location: {emp.location}")In this example, we create an Employee object and then set its attributes name, position, and location.
I executed the above Python code using VS code, and you can see the exact output in the screenshot below:

Check out Python Class Constructors with Parameters
Combine Empty and Parameterized Constructors
Sometimes, you might want to have the flexibility of both an empty constructor and a parameterized constructor. You can achieve this by setting default values for the parameters in the __init__ method.
Here’s an example:
class Employee:
def __init__(self, name=None, position=None, location=None):
self.name = name
self.position = position
self.location = location
# Creating an instance with no initial values
emp1 = Employee()
# Creating an instance with initial values
emp2 = Employee(name="Jane Smith", position="Data Scientist", location="New York")
print(f"Employee 1 Name: {emp1.name}")
print(f"Employee 2 Name: {emp2.name}")In this example, the Employee class constructor can accept parameters, but it also works without any parameters, thanks to the default None values.
I executed the above Python code, and you can see the exact output in the screenshot below:

Check out How to Call Super Constructor in Python?
Real Example: Dynamic Object Creation
Let me show you a real example of using an empty constructor in Python.
Suppose you are developing a web application for a company based in Los Angeles. The application requires creating user profiles dynamically based on user input from a form. An empty constructor can be beneficial here, as it allows you to create a user profile object first and then set its attributes based on the form data.
class UserProfile:
def __init__(self):
pass
# Creating a user profile object
user_profile = UserProfile()
# Setting attributes based on form input
user_profile.username = "johndoe123"
user_profile.email = "[email protected]"
user_profile.city = "Los Angeles"
print(f"Username: {user_profile.username}")
print(f"Email: {user_profile.email}")
print(f"City: {user_profile.city}")In this example, the UserProfile class has an empty constructor, and the attributes are set after the object is created, making it flexible to handle dynamic data.
Conclusion
In this tutorial, I explained how to create and use an empty constructor in Python. Whether you are working on a small project or a large-scale application, the ability to initialize objects dynamically and set their attributes is useful.

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.