Python OOP Tutorial 1 Classes and Instances Master the Basics

Logan Jul 13, 2026

Welcome to our comprehensive Python OOP tutorial focusing on classes and instances! If you're new to Object-Oriented Programming (OOP) in Python, you've come to the right place. By the end of this tutorial, you'll have a solid understanding of classes, instances, attributes, and methods – the cornerstones of OOP. Let's dive right in!

Python OOP Tutorial 1: Classes and Instances
Python OOP Tutorial 1: Classes and Instances

Python, with its elegant and readable syntax, is an excellent choice for learning OOP. It provides a clean and intuitive way to define and use classes and instances, making it easier for beginners to grasp the fundamental concepts. So, whether you're a seasoned programmer looking to expand your skillset or a novice developer eager to learn OOP, you're in the perfect spot!

Python Class and Objects With Code Examples - EasyCodeBook.com
Python Class and Objects With Code Examples - EasyCodeBook.com

Understanding Classes

A class in Python is like a blueprint for creating objects (instances). It defines a set of attributes and methods that characterize an object. Classes are created using the `class` keyword, followed by the class name and a colon.

Python Classes and Objects - OOP for Beginners
Python Classes and Objects - OOP for Beginners

Here's a simple example of what a class looks like in Python:

```python class Dog: def __init__(self, name, age): self.name = name self.age = age def bark(self): print(f"{self.name} says: Woof woof!") ```

In this example, we have a `Dog` class with two attributes: `name` and `age`. The `bark` method is also defined within the class, demonstrating a basic behavior of a dog.

Python Tutorial
Python Tutorial

Defining Attributes and Methods

Attributes are data variables that belong to an instance of a class. In the `Dog` class above, `name` and `age` are instance attributes. They store information about a specific dog, such as its name and age.

Methods are functions defined within a class. The `bark` method in our `Dog` class is an example of a method. It defines the behavior of a dog – in this case, making a dog bark. The `self` parameter is a reference to the instance of the class and is used to access instance attributes and methods.

an image of a page that has been edited with the text python oop object - oriented programming notes
an image of a page that has been edited with the text python oop object - oriented programming notes

Creating Instances

Now that we have defined our `Dog` class, we can create instances (objects) of this class. To do this, we use the class name followed by parentheses. Any arguments passed are used to initialize the instance attributes.

Let's create two `Dog` instances and use the `bark` method on them:

Classes and Objects in Python OOP - The Engineering Projects
Classes and Objects in Python OOP - The Engineering Projects

```python my_dog = Dog("Fido", 3) your_dog = Dog("Buddy", 5) my_dog.bark() # Outputs: Fido says: Woof woof! your_dog.bark() # Outputs: Buddy says: Woof woof! ```

As you can see, by creating instances of the `Dog` class, we can easily create and manipulate `Dog` objects with different attributes. This is the power of classes and instances in OOP.

Accessing and Manipulating Attributes

OOP in Python ✨ | Classes, Objects & 4 Pillars
OOP in Python ✨ | Classes, Objects & 4 Pillars
Python Projects Ideas For Beginners
Python Projects Ideas For Beginners
9 Python Projects for Beginners (Build Your Portfolio Fast)
9 Python Projects for Beginners (Build Your Portfolio Fast)
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
Python OOP Tutorial (Object Orientated Programming ) - Intro
Python OOP Tutorial (Object Orientated Programming ) - Intro
Classes and Objects with Python - Part 1 (Python Tutorial #9)
Classes and Objects with Python - Part 1 (Python Tutorial #9)
All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)
Master Python Methods: A Quick Guide for Beginners!
Master Python Methods: A Quick Guide for Beginners!
Python OOP Interview Questions – Advanced & Tricky Concepts Explained
Python OOP Interview Questions – Advanced & Tricky Concepts Explained
Python Notes for Beginners (Easy + Quick Guide)
Python Notes for Beginners (Easy + Quick Guide)
Fastest way to learn python for free.
Fastest way to learn python for free.
learn python with codehub
learn python with codehub
Python Learning Path for Beginners 2026 🚀
Python Learning Path for Beginners 2026 🚀
Python Object Oriented Programming (OOP) - For Beginners
Python Object Oriented Programming (OOP) - For Beginners
Easiest way to learn Python Programming.
Easiest way to learn Python Programming.
30 Python Projects For Beginners | Easy To Advanced Python Project Ideas
30 Python Projects For Beginners | Easy To Advanced Python Project Ideas
👩‍💻 Python for Beginners Tutorial
👩‍💻 Python for Beginners Tutorial
The OS Module | Python Tutorials For Beginners
The OS Module | Python Tutorials For Beginners
While loop in Python Easy to learn 🤩
While loop in Python Easy to learn 🤩

We can access and manipulate instance attributes using the dot notation. For example, to change the age of `your_dog`, we could do:

```python your_dog.age = 6 ```

Now, `your_dog.age` would equal 6. We can also access and manipulate attributes within methods, like this:

```python class Dog: # ... (same class definition as before) def update_age(self, years): self.age += years ```

In this updated `Dog` class, the `update_age` method increases the age of a dog by the specified number of years. This demonstrates how we can use methods to change the state of an object.

Inheritance and Polymorphism

Two essential concepts in OOP are inheritance and polymorphism. Inheritance allows us to create a new class (a subclass) that inherits attributes and methods from an existing class (a superclass). Polymorphism is the ability of objects of different classes to be treated as objects of a common (super)class.

To illustrate these concepts, let's create a `Puppy` subclass that inherits from the `Dog` class and overrides the `bark` method:

```python class Puppy(Dog): def __init__(self, name, age, breed): super().__init__(name, age) self.breed = breed def bark(self): print(f"{self.name} says: Yip yip!") ```

Here, `Puppy` inherits from `Dog` and adds a new `breed` attribute. The `bark` method is also overridden to make the sound a puppy makes. Now, creating a `Puppy` instance and calling its `bark` method would result in:

```python my_puppy = Puppy("Charlie", 1, "Labrador") my_puppy.bark() # Outputs: Charlie says: Yip yip! ```

This demonstrates polymorphism in action, as we can treat a `Puppy` instance as a `Dog` instance in many contexts, but it still behaves according to its own `bark` method.

Summary and Next Steps

In this tutorial, we've covered the basics of classes and instances in Python's object-oriented programming. We've seen how to define classes with attributes and methods, create instances, access and manipulate attributes, and even explored inheritance and polymorphism.

Python's OOP features are powerful and versatile, enabling you to model real-world objects and concepts in your code more efficiently. By understanding and applying the principles we've discussed, you'll be well on your way to mastering OOP in Python.

In our next tutorial, we'll delve deeper into OOP concepts, discussing encaptulation, abstraction, and other advanced topics. Until then, keep practicing and exploring the wonderful world of Python OOP!