Python is built on a single foundational idea: everything is an object. Understanding what that means — and how to work with it — is the first step toward writing real Python programs rather than just running scripts line by line.
When you assign a number to a variable, write a string, or build a list, Python represents each of those values as an object in memory. Objects are not just a feature you can choose to use — they are the underlying mechanism that Python uses to represent all data. This tutorial walks through what objects are, what they contain, and how to create your own.
What Is an Object?
An object is a self-contained unit of data and behavior. Every object in Python has three things: an identity (a unique location in memory), a type (which tells Python what kind of object it is), and a value (the actual data it holds).
You can confirm this yourself using Python's built-in functions. id() returns the memory address, type() returns the type, and the variable itself holds the value.
x = 42
print(id(x)) # memory address, e.g. 140234567891234
print(type(x)) # <class 'int'>
print(x) # 42
In Python, even the integer 42 is an object. It has a type (int), a value (42), and a unique identity in memory. This is true of every value you work with in the language.
The Python documentation describes this directly: every object has an identity, a type, and a value. The identity is fixed once the object is created. The type determines what operations are allowed. The value may or may not be changeable — objects whose value can change are called mutable, and those whose value cannot are called immutable.
"Objects are Python's abstraction for data." — The Python Language Reference, Python Software Foundation
A string like "hello" is immutable — you cannot change the characters in place. A list like [1, 2, 3] is mutable — you can append to it, remove items, or change a value at a given index. Both are objects.
Build the correct Python expression to check the type of the variable name:
type() is the built-in that returns an object's type. It must be nested inside print() to display the result. id() returns the memory address, not the type. value() does not exist as a built-in.
Attributes and Methods
Objects do not just hold data — they also carry behavior. The data stored inside an object is called an attribute. The functions that belong to an object and describe what it can do are called methods. Both are accessed using dot notation.
You have already been using attributes and methods without necessarily calling them by those names. When you call "hello".upper(), you are calling the upper method on a string object. When you check my_list.count(3), you are calling the count method on a list object.
# String object — calling a method
greeting = "hello world"
print(greeting.upper()) # HELLO WORLD
print(greeting.title()) # Hello World
# List object — calling a method and reading a built-in attribute
numbers = [4, 1, 7, 2]
numbers.sort()
print(numbers) # [1, 2, 4, 7]
print(len(numbers)) # 4 (len is a built-in that reads the object's size)
Type dir(some_object) in a Python shell to see all the attributes and methods available on any object. It works on strings, lists, integers — anything. This is a fast way to discover what an object can do without leaving your terminal.
The distinction between built-in objects (like strings and lists) and objects you define yourself is mostly about who wrote the class. The mechanics are identical. Both kinds have attributes and methods, both are created by calling a class, and both follow the same rules.
- What it is
- A variable that belongs to an object. It stores the data associated with that instance.
- How to access it
- Dot notation without parentheses, for example:
dog.nameordog.age.
- What it is
- A function that belongs to an object. It describes what the object can do or how it behaves.
- How to access it
- Dot notation with parentheses, for example:
dog.bark()orgreeting.upper().
- What it does
- The dot (
.) separates the object from the attribute or method name. It tells Python to look inside that specific object for the named thing. - Key point
- The dot works the same way whether you are accessing data (attribute) or calling a function (method). The only difference is whether parentheses follow.
Classes: The Blueprint for Objects
Before Python can create an object, it needs a blueprint that describes what the object will contain and what it can do. That blueprint is called a class. A class defines the structure; an object is an instance of that class created from the structure.
The relationship is similar to how a form template works. The template defines which fields exist. Each filled-out copy of the form is a separate instance, with its own specific values in those fields — but they all share the same structure because they came from the same template.
class Dog:
def __init__(self, name, age):
self.name = name # attribute
self.age = age # attribute
def bark(self): # method
print(f"{self.name} says: Woof!")
# Create two separate Dog objects from the same class
dog_one = Dog("Biscuit", 3)
dog_two = Dog("Maple", 5)
dog_one.bark() # Biscuit says: Woof!
dog_two.bark() # Maple says: Woof!
print(dog_one.age) # 3
print(dog_two.name) # Maple
A few things to notice in that example. First, class Dog: defines the blueprint. Second, __init__ is a special method that Python calls automatically when you create a new instance — it sets the initial attribute values. Third, self is a reference to the specific instance being created or used. It appears as the first parameter of every method but you do not pass it in yourself — Python handles that automatically.
Forgetting to include self as the first parameter in a method definition is one of the most common errors beginners encounter. Python will raise a TypeError when you try to call the method, because the instance is passed automatically but the method has nowhere to receive it.
This class definition has one bug. Click the line you think is wrong, then hit check.
Color to color on line 4. Python variable names are case-sensitive. Color is not defined anywhere, so Python would raise a NameError when you try to create a Cat object. The parameter passed into __init__ is lowercase color, and that is the name you must use.
How to Create an Object in Python
Creating an object from scratch takes five steps. Each one builds on the last, and by the end you will have a working class with attributes and methods that you can instantiate and use.
-
Define a class
Use the
classkeyword followed by the class name and a colon. By convention, class names use CamelCase (for example,BankAccount, notbank_account). Everything indented beneath the class definition belongs to the class. -
Write the __init__ method
Inside the class, define
__init__(self, ...). List any data each object should store as parameters afterself. Inside the method body, assign each parameter to an attribute usingself.attribute_name = parameter_name. Python calls this method automatically every time you create a new instance. -
Add a method
Define additional methods beneath
__init__usingdef. Always includeselfas the first parameter. Inside the method, useself.attribute_nameto read or change the object's data. A method can return a value, print output, or modify the object's state. -
Instantiate the class
Outside the class definition, call the class name like a function:
my_object = ClassName(arg1, arg2). Pass the required arguments that match the parameters in__init__(not includingself). Python creates a new object in memory and returns a reference to it. -
Access attributes and call methods
Use dot notation to read attributes (
my_object.name) or call methods (my_object.greet()). Each instance you create keeps its own copy of the attribute values. Changing an attribute on one instance does not affect any other instance.
# Step 1 — Define the class
class BankAccount:
# Step 2 — Write __init__
def __init__(self, owner, balance):
self.owner = owner
self.balance = balance
# Step 3 — Add a method
def deposit(self, amount):
self.balance += amount
print(f"Deposited {amount}. New balance: {self.balance}")
def get_balance(self):
return self.balance
# Step 4 — Instantiate
account = BankAccount("Taylor", 500)
# Step 5 — Access attributes and call methods
print(account.owner) # Taylor
account.deposit(150) # Deposited 150. New balance: 650
print(account.get_balance()) # 650
Python Learning Summary Points
- Every value in Python is an object. Integers, strings, lists, functions, and instances of your own classes are all objects with an identity, a type, and a value.
- A class is a blueprint. An object is an instance of that blueprint. Calling the class with arguments creates a new object in memory.
- Attributes store an object's data. Methods are functions attached to the object that describe what it can do. Both are accessed with dot notation.
__init__is the initializer method. Python calls it automatically when you create a new instance, setting the object's starting attribute values.selfrefers to the current instance. It must appear as the first parameter of every method, but Python passes it automatically — you do not supply it when calling the method.
From here, the natural next steps are learning about inheritance (where one class can extend another) and special methods (also called dunder methods) that let your objects respond to built-in operations like +, len(), and print(). But those build directly on what you have learned here: objects have data, objects have behavior, and everything in Python is an object.
Frequently Asked Questions
In Python, an object is a self-contained unit that bundles together data (called attributes) and the behaviors that operate on that data (called methods). Every value in Python — integers, strings, lists, and instances of your own classes — is an object.
A class is a blueprint or template that describes what data and behaviors an object will have. An object is a specific instance created from that blueprint. For example, Dog is a class; the specific dog named Biscuit with a given breed and age is an object (an instance of Dog).
__init__ is a special method in Python called the constructor. Python calls it automatically when a new instance of a class is created. It is where you set the initial attribute values for the object.
self refers to the current instance of the class. When you define a method inside a class, the first parameter is always self, which allows the method to access and modify the object's own attributes. Python passes it automatically when you call a method — you do not include it in your call.
Yes. In Python, every value is an object. Integers, floats, strings, lists, functions, and even classes themselves are all objects. This is a core design principle of the language and a major reason Python behaves consistently across different data types.
An attribute is a variable that belongs to an object. It stores data associated with that specific instance. You access an attribute using dot notation, for example: dog.name or dog.age. Each object instance holds its own copy of attribute values.
A method is a function defined inside a class that describes what an object can do. Methods always take self as their first parameter so they can access the object's attributes. You call a method using dot notation with parentheses, for example: dog.bark().
You create an object by calling the class name like a function. For example, if you have a class called Dog, you would write my_dog = Dog('Biscuit', 3) to create a new instance. Python automatically calls the __init__ method with the arguments you pass.