Table of contents
1.
Introduction
2.
What is an Object in Python?
2.1.
Everything in Python is an Object 
3.
Creating a Python Object
4.
Accessing Object's variables in Python
4.1.
Python
4.2.
Accessing Object's functions in Python
4.3.
Python
4.4.
Modifying Object's properties in Python
4.5.
Python
4.6.
Deleting Object's properties in Python
4.7.
Python
5.
Consider the following 
6.
Built-in Class and User Class 
7.
Frequently Asked Questions
7.1.
Why is Python an object?
7.2.
What is the class and object?
7.3.
What is an object in programming?
8.
Conclusion 
Last Updated: Aug 21, 2025
Easy

Object in Python

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Python deservedly has a reputation for being an easy language to read and write. It’s got great documentation and a community that is very welcoming to beginners.

As we dig deeper, we may find many aspects of the Python language that surprise us, as one aspect that deserves in-depth explanation is How Everything in Python is an Object? Since Python is an object-oriented programming language, everything in Python is an object, every integer, string, list, and function. 

Introduction image

What is an Object in Python?

Python is an object-oriented language, and everything in Python is an object. An object is an entity that stores data as attributes and provides methods to operate on that data. Objects act as building blocks of programs, with multiple instances coexisting in a single application. In Python, even strings, lists, functions, and modules are objects, highlighting its flexible and unified design.

Everything in Python is an Object 

In Python, almost everything is an object, whether a number, a function, or a module. Python is using a pure object model where classes are instances of a meta-class “type” in Python, the terms “type” and “class” are synonyms. And “type” is the only class that is an instance of itself. This object model can be useful when we want information about a particular resource in Python. Except for the Python keywords like “if def, globals”, using type(<name>) or dir(<name>) or just typing the resource name and pressing enter- it will work on pretty much anything. Let’s make it clear what this statement means “Everything in Python is an object”.

Creating a Python Object

In Python, objects are instances of classes, which define their structure and behavior. A class serves as a blueprint for creating objects, specifying the attributes (data) and methods (functions) that the objects will possess. To create an object, you first define a class and then instantiate it by calling the class as if it were a function.

Let's see how to create a Python object :

  • Define a class using the `class` keyword, followed by the class name and a colon.
  • Inside the class, define the `__init__()` method (constructor) to initialize the object's attributes. It is automatically called when an object is created.
  • Specify any attributes as instance variables within the `__init__()` method using the `self` keyword.
  • Define any additional methods within the class to specify the behavior and actions of the objects.
  • Create an object (an instance of the class) by calling the class name followed by parentheses, passing any required arguments to the constructor.
  • Access and modify the object's attributes using dot notation: `object.attribute`.
  • Call methods on the object using dot notation: `object.method()`.

For example

class Rectangle:
   def __init__(self, width, height):
       self.width = width
       self.height = height
   def calculate_area(self):
       return self.width * self.height
# Create objects of the Rectangle class
rectangle1 = Rectangle(5, 3)
rectangle2 = Rectangle(7, 4)
# Access object attributes
print(rectangle1.width)  # Output: 5
print(rectangle2.height)  # Output: 4
# Call object methods
area1 = rectangle1.calculate_area()
area2 = rectangle2.calculate_area()
print(area1)  # Output: 15
print(area2)  # Output: 28
You can also try this code with Online Python Compiler
Run Code

In this example, we define a `Rectangle` class with a constructor that takes `width` and `height` as parameters. The constructor initializes the `width` and `height` attributes of the object. We also define a `calculate_area()` method that calculates and returns the area of the rectangle.

We create two objects, `rectangle1` and `rectangle2`, by calling the `Rectangle` class and passing the respective width and height values. We can access the attributes of each object using dot notation and call the `calculate_area()` method to compute the area of each rectangle.

Accessing Object's variables in Python

To access the variable value in python, you can use the dot(.) notation. Accessing object variables, also known as a data value or attribute, can be done by using a dot.

To understand this better, let's consider an example: The __init__ method in Python classes gets called when you create an instance of the class

  • Python

Python

class EmployeeDetails:
def __init__(self, empname, empid):
self.empname = empname
self.empid = empid

my_instance = EmployeeDetails(empname="Rohan", empid=5)


print(my_instance.empname)
print(my_instance.empid)
You can also try this code with Online Python Compiler
Run Code

Output

Output

Accessing Object's functions in Python

In Python, you can access function values using dot notation. In Python, using the dot(notation), you can invoke or call a method. Let's see the below example for a better understanding: 

  • Python

Python

class EmployeeDetails:
def __init__(self, empname, empid):
self.empname = empname
self.empid = empid

def details(self):
return f"{self.empname,self.empid}!"
Employee = EmployeeDetails(empname="Mohit Khatri", empid=150176)
show = Employee.details()
print(show)
You can also try this code with Online Python Compiler
Run Code

Output

Output

Modifying Object's properties in Python

In Python, you can access function values and also modify them using dot notation. In Python, using the dot(notation), you can assign a new value in the method. Let's see the example below for a better understanding: 

  • Python

Python

class EmployeeDetails:
def __init__(self, empname, empid):
self.empname = empname
self.empid = empid

def show(self):
return f"{self.empname, self.empid}"

Employee = EmployeeDetails(empname="Ria Jain", empid = 6789)

print(f"Before update: {Employee.empname} Employeeid is {Employee.empid}")


Employee.empname = "Shivam Rajput"
Employee.empid = 4789

print(f"After update: {Employee.empname} Employeeid is {Employee.empid}")
You can also try this code with Online Python Compiler
Run Code

Output

Output

Deleting Object's properties in Python

To delete an object property in Python, del keyword is used. 

Syntax

del variable_name property

After deleting a property or class variable properties delete, you cannot access the deleted value. Once you delete the value of the object, and later when you try to access it, you encounter an error message. Below is an example for better understanding: 

  • Python

Python

class EmployeeDetails:
def __init__(self, empname, empid):
self.empname = empname
self.empid = empid

def show(self):
return f"{self.empname, self.empid}"

Employee = EmployeeDetails(empname="Ria Jain", empid = 6789)

print(f"Before delete: {Employee.empname} Employeeid is {Employee.empid}")

del Employee.empid
print(f"After delete: {Employee.empname} Employeeid is {Employee.empid}")
You can also try this code with Online Python Compiler
Run Code

Output

Output

Consider the following 

Code

As we know it very well that Python has types; however, the types are linked not to the variable names but to the object themselves. Earlier in object-oriented programming languages like Python, an object is an entity that contains data along with associated metadata and/or functionality. In Python, everything is an object, which means every entity has some metadata called “attributes” and associated functionality called “methods”. These attributes and methods are accessed via the dot syntax.

For example, we saw that lists have an append method, which adds an item to the list and is accessed via the dot (“.”) syntax:

Code

While it might be expected for compound objects like lists to have attributes and methods, what is sometimes unexpected is that in Python even simple types have attached attributes and methods.

For example, numerical types have a real and image attribute that returns the real and imaginary part of the value, if viewed as a complex number.

Code

Methods are like attributes, except they are functions that you can call using opening and closing parentheses. For example, floating point numbers have a method called is_integer that checks whether the value is an integer. 

Code

When we say that everything in Python is an object, we really mean that everything is an object – even the attributes and methods of objects are themselves objects with their own type information:

Code

Implementation through C programming language:-

Let’s now dive into the C implementation to see how objects are represented.

Those objects are manipulated under the hood as a C structure called PyObject. Ironically, the CPython object model is implemented using C, a language that is not object-oriented. From there, we will notice the two following attributes:

  • Firstly a reference count, which keeps track of how many other objects and variables reference it. This is changed in the C code through the macros Py_INCREF() and Py_DECREF().
     
  • Secondly, a type (PyTypeObject structure), allows Python to determine the type or class of the object at runtime. That type contains various methods used to describe the class's behavior. What function to call to allocate the type, to deallocate the type, to cast as a number, etc?

Built-in Class and User Class 

Python comes with some built-in classes, such as int, str, and list, but also functions or classes. Contrary to a language such as Ruby, where everything is also an object, Python does not allow adding new attributes or methods to the built-in types such as int or str.

The declarations of these objects are in the Include directory, and we can find in Object the various implementations of several types:

int (Objects/longobject.c), str (Objects/unicodeobject.c), list (Objects/listobject.c), user-defined classes (Objects/classobject.c), functions (Objects/funcobject.c), etc.

Each of those files defines a PyTypeObject instance which represents the type. Each PyTypeObject instance contains mostly functions that describe the behavior of the type.

For example, tp_getattro and tp_setattro, when defined, are the functions that allow to respectively read and assign a value to an attribute. The absence of tp_setattro for the “int” type explains why it is not possible to add or change an attribute to an integer. tp_as_sequence and tp_as_mapping point to lists of methods to handle standard functions for functions and dictionaries.

When the program is defining a user class, the runtime creates a new type for that class.

Frequently Asked Questions

Why is Python an object?

Like any other programming language, python allows you to define the classes and later create objects of those classes. A class in Python is a collection of instance variables and methods that help in defining the object for that class. 

What is the class and object?

A class is nothing but a blueprint for creating objects. It is like an object constructor. An object is an instance of a class that helps in defining the class methods and variables. 

What is an object in programming?

An object in programming is defined as a data field that consists of unique fields and its values. It contains the information of uniquely identifying the attributes. An object in Python is created using the constructor of the class and then this object will be called an instance of the class. 

Conclusion 

In Python, everything is treated as an object, reflecting the object-oriented approach of combining data with functions. Objects act as abstractions that simplify programming by grouping related attributes and methods together. Unlike primitive types in languages like C, even numbers in Python are objects, allowing them to carry properties and behaviors such as being prime or even.

Recommended Readings:

 

Live masterclass