Hey Python newbies and curious cats! 👋
You've probably heard the legendary phrase:
"Everything is an object in Python."
But what does that actually mean?
Why are numbers objects?
Why are functions objects?
How can classes themselves be objects?
And what exactly is a metaclass?
By the end of this article, you'll understand one of Python's most important concepts and gain a deeper appreciation for how Python works behind the scenes.
What Is an Object in Python?
An object is a piece of data that contains:
- Identity
- Type
- Value
Everything that exists at runtime in Python is represented as an object.
Example:
x = 5
The value 5 is not merely a number.
It is an object created from Python's built-in int class.
print(type(x))
# <class 'int'>
Objects can expose attributes and methods:
print(x.bit_length())
Output:
3
Because binary 101 requires three bits.
Everything Has a Type
Every Python object belongs to a class.
print(type(42))
print(type("hello"))
print(type([1, 2, 3]))
print(type({"name": "Anik"}))
Output:
<class 'int'>
<class 'str'>
<class 'list'>
<class 'dict'>
The type determines:
- Available methods
- Supported operations
- Object behavior
Classes Are Objects Too
Here's where things become interesting.
Consider:
class Person:
pass
Most beginners think classes are simply blueprints.
But in Python:
print(type(Person))
Output:
<class 'type'>
This means:
Classes are objects.
The class itself exists in memory as an object.
Why Does This Matter?
Because classes can be treated exactly like other objects.
You can:
Assign Them to Variables
Alias = Person
print(Alias)
Pass Them as Function Arguments
def create_instance(cls):
return cls()
instance = create_instance(Person)
Return Them from Functions
def get_model():
return Person
Create Them Dynamically
DynamicUser = type(
"DynamicUser",
(),
{
"role": "admin"
}
)
print(DynamicUser.role)
Output:
admin
Understanding type()
Most developers use:
type(obj)
to inspect object types.
However, type itself is also an object.
print(type(int))
print(type(str))
print(type(list))
Output:
<class 'type'>
<class 'type'>
<class 'type'>
This means:
typecreates classes.
Meet the Metaclass
A metaclass is simply:
A class that creates classes.
The default Python metaclass is:
type
When Python executes:
class User:
pass
Internally Python does something similar to:
User = type(
"User",
(),
{}
)
The Mind-Bending Part: Why Is type(type) Equal to type?
Try this:
print(type(type))
Output:
<class 'type'>
At first glance this looks impossible.
How can something be an instance of itself?
Python's Bootstrap Process
The answer lives inside CPython.
When Python starts:
- The interpreter creates core objects manually in C.
- The
typeobject is constructed. - Python establishes a self-referential relationship.
- The object system becomes operational.
This process is called:
Bootstrapping
Without it, Python's object system could not initialize itself.
A Real-World Analogy
Imagine a factory that builds robots.
Normally:
- Factory → builds robots
But what if the factory itself is also a robot?
Engineers first build the factory manually.
After that:
- Factory builds robots
- Factory can build robot versions of itself
This is essentially how Python bootstraps type.
Identity, Type, and Value
Every Python object contains three fundamental characteristics.
Identity
Unique memory reference.
x = 10
print(id(x))
Type
Object classification.
print(type(x))
Output:
<class 'int'>
Value
Actual stored data.
x = 10
Value:
10
Functions Are Objects
Functions are first-class citizens in Python.
def greet():
print("Hello")
You can attach attributes:
greet.language = "English"
print(greet.language)
Output:
English
You can also:
- Pass functions
- Return functions
- Store functions inside objects
This capability powers:
- Decorators
- Callbacks
- Functional programming
Modules Are Objects
Even imported modules are objects.
import math
print(type(math))
Output:
<class 'module'>
Instances Are Objects
Classes create object instances.
class Person:
def __init__(self, name):
self.name = name
user = Person("Alice")
print(type(user))
Output:
<class '__main__.Person'>
Introspection: Exploring Objects at Runtime
Python provides powerful introspection tools.
type()
id()
dir()
isinstance()
hasattr()
getattr()
Example:
user = Person("Alice")
print(dir(user))
This helps developers inspect objects dynamically.
Why Understanding Python Objects Matters
Understanding Python's object model helps with:
- Object-Oriented Programming
- Django development
- FastAPI development
- Framework internals
- Debugging
- Performance optimization
- Metaprogramming
- Technical interviews
Many advanced Python concepts become easier once you understand how objects work.
Frequently Asked Questions
What does "Everything is an Object in Python" mean?
Every value in Python is represented as an object, including integers, strings, functions, classes, and modules.
Are integers objects in Python?
Yes.
x = 42
print(type(x))
Output:
<class 'int'>
Are strings objects in Python?
Yes.
Strings are immutable objects of type str.
Are functions objects in Python?
Absolutely.
Functions can store attributes and be passed around like any other object.
Are classes objects in Python?
Yes.
Classes are objects created by the metaclass type.
What is a metaclass in Python?
A metaclass is a class responsible for creating other classes.
Python uses type as the default metaclass.
Why is type(type) equal to type?
Because Python bootstraps its object system and establishes a special self-referential relationship for the type object.
What is introspection in Python?
Introspection allows developers to inspect object information at runtime using tools such as:
type()
id()
dir()
isinstance()
Are modules objects in Python?
Yes.
Imported modules are instances of Python's module type.
Is Python fully object-oriented?
Python is highly object-oriented, but it also supports procedural, functional, and metaprogramming paradigms.
Why should every Python developer understand the object model?
Because it forms the foundation of:
- Classes
- Inheritance
- Framework internals
- Metaprogramming
- Advanced Python development
Key Takeaways
- Everything in Python is an object.
- Every object has identity, type, and value.
- Numbers, strings, functions, modules, and classes are objects.
- Classes are objects created by the metaclass
type. - Functions are first-class objects.
- Python's object model powers inheritance and introspection.
- Understanding the object model is essential for mastering Python.
About the Author
Anik Sikder is a Software Engineer specializing in Python, Django, FastAPI, Cloud Infrastructure, DevOps, and Software Architecture.
He writes about Python Internals, System Design, Distributed Systems, JavaScript, Cloud Computing, and scalable software engineering practices.



