Everything is an Object in Python: From Beginner to “Wait, What?!” Level
Anik Sikder

Anik Sikder @anik_sikder_313

About: Full-Stack Dev & Tech Writer | Python (Django, FastAPI), JS (React, Next.js) | I build fast, scalable apps & write on backend, frontend, APIs & Web3 | Open to freelance/remote roles

Location:
Dhaka, Bangladesh
Joined:
Aug 6, 2025

Everything is an Object in Python: From Beginner to “Wait, What?!” Level

Publish Date: Aug 9
0 0

Hello Python learners and curious developers! You’ve probably come across this popular saying in the programming world:

“Everything is an object in Python.”

It sounds almost mystical, right? Well, it kind of is this concept is one of the core reasons Python is so flexible and powerful. So, fasten your seatbelt! This post will take you from the basics of “What exactly is an object?” all the way to the more mind-boggling concept of metaclasses.

Let's keep it light, fun, and easy to digest no dry lectures here!


What Exactly is an Object?

In Python, an object is simply a container that holds data and the functions that operate on that data think of it like a combo meal with fries and a drink. Objects have attributes (the data) and methods (actions they can perform).

Take this example:

a = 5
Enter fullscreen mode Exit fullscreen mode

That 5 isn’t just a number; it’s an object of the type int. This object even has special abilities, like .bit_length() which tells how many bits it takes to represent the number in binary.

Try it yourself:

print(type(a))        # <class 'int'>
print(a.bit_length()) # 3 (because 5 is 101 in binary)
Enter fullscreen mode Exit fullscreen mode

So, a isn’t a plain number; it’s a complete Python object.


Every Object Has a Type

Every object in Python wears a label called a type that tells Python what kind of object it is and what operations it supports.

print(type(5))          # <class 'int'>
print(type("hello"))    # <class 'str'>
print(type([1, 2, 3]))  # <class 'list'>
Enter fullscreen mode Exit fullscreen mode

This type information decides what you can do with the object like adding numbers, slicing strings, or appending to lists.


Surprise! Classes Are Objects, Too!

Here’s where it gets really cool: classes themselves are objects!

When you define a class, Python creates a class object. Think of this class object as a blueprint object that can create other objects.

Example:

class MyClass:
    pass

print(type(MyClass))  # <class 'type'>
Enter fullscreen mode Exit fullscreen mode

Notice that MyClass is an object of the type type. Yes, the class itself is an object!


Why Is This Useful?

Because classes are objects, you can:

  • Assign them to variables:
Alias = MyClass
print(Alias)  # <class '__main__.MyClass'>
Enter fullscreen mode Exit fullscreen mode
  • Pass them around in your code like any other object.

  • Create classes dynamically:

Dynamic = type('Dynamic', (), {'x': 10})
print(Dynamic.x)  # 10
Enter fullscreen mode Exit fullscreen mode

Here, type() acts like a class factory that builds new classes on demand. Cool, right?


Meet the Metaclass: The Class of Classes

type is known as a metaclass it’s the class that creates classes.

print(type(MyClass))  # <class 'type'>
print(type(int))      # <class 'type'>
print(type(type))     # <class 'type'>
Enter fullscreen mode Exit fullscreen mode

Even type itself is an instance of type a self-referential concept that can make your head spin!


Identity, Type, and Value The Three Pillars of Python Objects

Every Python object has:

  • Identity: Like a social security number, unique for each object.
print(id(a))
Enter fullscreen mode Exit fullscreen mode
  • Type: What kind of object it is (int, list, etc.).

  • Value: The actual data it holds (like [1, 2, 3] or "Hello!").


Objects Are Everywhere in Python

Did you know functions are objects, too? You can even add attributes to them!

def greet():
    print("Hello!")

greet.language = 'English'
print(greet.language)  # English
Enter fullscreen mode Exit fullscreen mode

Modules? Also objects:

import math
print(type(math))  # <class 'module'>
Enter fullscreen mode Exit fullscreen mode

Classes create instances objects born from their blueprints:

class Person:
    def __init__(self, name):
        self.name = name

p = Person("Alice")
print(type(p))   # <class '__main__.Person'>
print(p.name)    # Alice
Enter fullscreen mode Exit fullscreen mode

Why Should You Care?

Understanding that everything is an object helps you:

  • See why Python is so flexible and expressive.

  • Write dynamic code using metaprogramming techniques.

  • Debug and design programs more effectively.

  • Impress your peers with your deep Python knowledge.


Final Thoughts

“Everything is an object” isn’t just a phrase it’s a foundational concept that unlocks Python’s power.

From basic numbers to complex metaclasses, mastering objects will take your Python skills to the next level.

Feel free to leave questions or share your own Python object stories in the comments!

Happy coding! 🚀🐍

Comments 0 total

    Add comment