Last modified: Nov 26, 2026

Python Class Without __init__ Explained

A Python class does not always need an __init__ method. You can create a class with no constructor at all.

This is common for simple classes. It is also useful for grouping static methods or storing class-level data.

This guide explains how a Python class works without __init__. It covers attributes, methods, instances, and common mistakes.

What Is a Python Class Without __init__?

A class is a blueprint for objects. The __init__ method sets up instance attributes when you create an object.

If you skip __init__, Python still creates the object. It just does not run any setup code.

Here is a minimal class. It has no constructor and no attributes.


class Empty:
    pass

obj = Empty()
print(obj)

<__main__.Empty object at 0x7f8b1c2a3d90>

The object exists. It simply holds no custom data yet.

If you want a deep dive into the constructor itself, read this guide to the Python Class __init__ Method Guide.

Why Skip __init__?

Many beginners think every class needs a constructor. That is not true.

You can skip __init__ when the class has no per-instance setup. A class that only holds constants or helper methods works fine without it.

Skipping it also keeps small classes short. Less code means fewer bugs.

Some classes are just namespaces. They group related functions under one name.


class MathHelper:
    # No __init__ needed here
    def double(x):
        return x * 2

    def square(x):
        return x * x

print(MathHelper.double(5))
print(MathHelper.square(5))

10
25

This works, but the methods are called on the class. They are not bound to an instance.

Adding Attributes Without __init__

You can still add attributes to an object after creation. Python allows this for most normal classes.

Just assign a value to self or to the instance. The attribute appears at runtime.


class Person:
    pass

p = Person()
p.name = "Alice"   # add attribute after creation
p.age = 30

print(p.name, p.age)

Alice 30

This is flexible. But it can be messy. Attributes are not guaranteed to exist.

Use class attributes when the value is shared. Use instance attributes when each object needs its own value.

Class Attributes vs Instance Attributes

A class attribute lives on the class. Every instance can see it.

An instance attribute lives on one object. Other objects do not see it.


class Counter:
    count = 0   # class attribute

c1 = Counter()
c2 = Counter()

print(c1.count, c2.count)  # both see the class attribute
c1.count = 5               # creates an instance attribute on c1
print(c1.count, c2.count)  # c2 still sees the class value

0 0
5 0

This behavior surprises many beginners. Assigning to c1.count does not change the class attribute.

It only adds a new attribute to c1. The class value stays the same.

Be careful with mutable class attributes. Lists and dicts are shared across all instances.


class BadBox:
    items = []   # shared by all instances

a = BadBox()
b = BadBox()
a.items.append("x")

print(b.items)  # b sees a's change

['x']

This is a common bug. Use __init__ to create a fresh list per object.

Methods That Use self

A method can still use self without __init__. It just reads or sets attributes when called.


class Greeter:
    def greet(self):
        # fallback value if name is missing
        name = getattr(self, "name", "stranger")
        return f"Hello, {name}!"

g = Greeter()
print(g.greet())

g.name = "Bob"
print(g.greet())

Hello, stranger!
Hello, Bob!

The getattr function gives a safe default. This avoids errors when an attribute is missing.

You can also use hasattr to check for an attribute before reading it.

The Role of the Default Constructor

Even without __init__, Python gives your class a default constructor. It comes from the base object class.

You can call it directly. It takes no arguments and does nothing extra.


class Plain:
    pass

p = Plain()          # works, no __init__ defined
print(type(p).__mro__)  # shows the class hierarchy

(, )

This is why instantiation works. The parent class provides the default behavior.

To learn more about inheritance and base classes, see the Python super() Function Explained.

Using Class Decorators

You can modify a class without touching __init__. Class decorators let you wrap or extend a class.

They are handy for adding behavior like logging or registration.


def register(cls):
    # attach a simple flag to the class
    cls.registered = True
    return cls

@register
class Service:
    pass

print(Service.registered)

True

This technique is powerful but easy to overuse. Keep decorators small and focused.

For more patterns, read the Python Class Decorator Guide.

Static Methods and Class Methods

Some classes only need helper functions. Static methods do not use self or cls.

Class methods receive the class itself. They are useful for factory-style creation.


class Temp:
    @staticmethod
    def to_fahrenheit(c):
        return c * 9 / 5 + 32

    @classmethod
    def freezing_point(cls):
        return cls.to_fahrenheit(0)

print(Temp.to_fahrenheit(100))
print(Temp.freezing_point())

212.0
32.0

No constructor is needed here. The class is just a container for related logic.

When You Should Add __init__

Skip __init__ for simple cases. Add it when objects need required data at creation.

Use it when you need validation. It is also the right place for default values and mutable setup.

Without it, users must set attributes manually. That is error-prone and hard to document.


class Account:
    def __init__(self, owner, balance=0):
        self.owner = owner
        self.balance = balance

    def deposit(self, amount):
        self.balance += amount

acc = Account("Alice", 100)
acc.deposit(50)
print(acc.owner, acc.balance)

Alice 150

This version is safer. Every account starts with a valid owner and balance.

Common Mistakes to Avoid

Mistake one: assuming attributes always exist. Without __init__, they may be missing.

Mistake two: using mutable class attributes. Shared lists and dicts cause hidden bugs.

Mistake three: forgetting self in instance methods. The method then fails when called on an object.

Mistake four: calling a method with wrong arguments. Always check the signature.

You can inspect signatures at runtime. This helps when debugging tricky calls.

See the Python Inspect Function Signature Guide for details.

Best Practices

Keep classes small and focused. A class should do one job well.

Prefer explicit setup over hidden attribute creation. Clear code beats clever code.

Use class attributes for constants. Use instance attributes for per-object state.

Add type hints where possible. They make your intent clear.

Write short tests for each method. Tests catch missing attributes early.

Quick Recap

A Python class does not require __init__. It works fine without one.

You can add attributes later. You can also use class attributes and static methods.

But __init__ is the cleanest place for required setup. Use it when objects need data at birth.

Conclusion

A Python class without __init__ is valid and useful. It fits simple containers, helpers, and namespace-style classes.

Still, know the trade-offs. Missing setup can lead to fragile objects and hidden bugs.

Choose the simplest design that stays clear. Add __init__ when it makes your code safer and easier to read.