Python OOP Concepts Explained with Simple Examples for Beginners
Published: 23 Oct, 2026 | Author: CCI Admin | Category: Python / Programming / OOP
Object-Oriented Programming (OOP) is one of the most important concepts in Python programming. It helps developers organize code into reusable components, making applications easier to develop, understand, test, and maintain.
In this beginner-friendly guide, you will learn the four main principles of Python OOP: encapsulation, inheritance, polymorphism, and abstraction, along with classes, objects, and practical examples.
What Is Object-Oriented Programming in Python?
Object-Oriented Programming is a programming approach that organizes code using classes and objects. An object combines data (attributes) and behavior (methods) into one unit.
For example, a student management application can use a Student class to store student names, register numbers, and marks, while methods perform actions such as displaying student details.
1. Classes and Objects in Python
What Is a Class?
A class is a blueprint used to create objects. It defines the attributes and methods that its objects can have.
What Is an Object?
An object is an instance of a class. Multiple objects can be created from the same class with different data.
Example: Student Class
class Student:
def __init__(self, name, mark):
self.name = name
self.mark = mark
def display(self):
print("Student Name:", self.name)
print("Mark:", self.mark)
s1 = Student("Arun", 85)
s2 = Student("Priya", 92)
s1.display()
s2.display()
Output
Student Name: Arun
Mark: 85
Student Name: Priya
Mark: 92
Here, Student is the class, s1 and s2 are objects, and
__init__() initializes each object's data.
The self parameter refers to the current object.
2. The Four Main Principles of Python OOP
A. Encapsulation
Encapsulation means grouping data and methods inside a class and controlling how the data is accessed or modified. Python uses conventions and properties to help manage access to attributes.
class BankAccount:
def __init__(self, balance):
self.__balance = balance
def deposit(self, amount):
if amount > 0:
self.__balance += amount
def show_balance(self):
print("Balance:", self.__balance)
account = BankAccount(1000)
account.deposit(500)
account.show_balance()
Output
Balance: 1500
The double underscore in __balance triggers name
mangling in Python. It discourages direct access but is not
absolute security.
B. Inheritance
Inheritance allows a child class to reuse or extend attributes and methods from a parent class. It reduces code duplication.
class Animal:
def eat(self):
print("Animal is eating")
class Dog(Animal):
def bark(self):
print("Dog is barking")
d = Dog()
d.eat()
d.bark()
Output
Animal is eating
Dog is barking
The Dog class inherits the eat() method from Animal
and also defines its own bark() method.
C. Polymorphism
Polymorphism means that the same method name or interface can produce different behavior depending on the object using it.
class Dog:
def sound(self):
print("Dog barks")
class Cat:
def sound(self):
print("Cat meows")
animals = [Dog(), Cat()]
for animal in animals:
animal.sound()
Output
Dog barks
Cat meows
Both classes define sound(), but each object produces
its own result. This is an example of polymorphism.
D. Abstraction
Abstraction hides implementation details and exposes the essential
operations. Python supports abstraction through abstract base classes
in the abc module.
from abc import ABC, abstractmethod
class Payment(ABC):
@abstractmethod
def pay(self, amount):
pass
class UpiPayment(Payment):
def pay(self, amount):
print("Paid Rs.", amount, "using UPI")
payment = UpiPayment()
payment.pay(500)
Output
Paid Rs. 500 using UPI
The Payment class defines the required method, while UpiPayment provides its implementation. A concrete subclass must implement the abstract method before it can be instantiated.
3. Python OOP Concepts at a Glance
| Concept | Meaning | Example |
|---|---|---|
| Class | Blueprint for creating objects | Student |
| Object | Instance of a class | A particular student |
| Encapsulation | Organizes data and methods and manages access | Bank account |
| Inheritance | Reuses and extends existing class behavior | Dog inherits from Animal |
| Polymorphism | Same interface, different behavior | Different animal sounds |
| Abstraction | Exposes essential operations and hides implementation details | Payment interface |
4. Real-World Applications of Python OOP
Python OOP is useful in many types of software projects, including:
- Student Management Systems
- Banking and billing applications
- E-commerce websites
- Hospital Management Systems
- Employee Management Systems
- Game development and simulation projects
5. Advantages of Object-Oriented Programming
- Code can be organized into reusable classes.
- Inheritance helps reduce repeated code.
- Classes make large projects easier to maintain.
- Encapsulation helps manage access to data.
- Polymorphism supports flexible and extensible designs.
6. Common Mistakes Beginners Should Avoid
- Forgetting to use
selfin instance methods. - Confusing a class with an object.
- Forgetting parentheses when creating an object.
- Incorrectly calling methods or passing arguments.
- Assuming a double-underscore attribute is completely private or secure.
Faculty Tip from CCI Computer Education
Students should practise one OOP concept at a time. Start with classes and objects, then learn inheritance, polymorphism, encapsulation, and abstraction. Build small projects to understand how these concepts work together in real applications.
Practice Tasks for Students
- Create a Student class with name, register number, and marks.
- Create an Employee class with a method to display employee details.
- Create a Vehicle parent class and Car child class to practise inheritance.
- Create two classes with the same method name to demonstrate polymorphism.
- Create an abstract Shape class with a method for calculating area.
Frequently Asked Questions (FAQs)
1. What is OOP in Python?
OOP is a programming approach that uses classes and objects to organize data and behavior into reusable components.
2. What are the four main principles of OOP?
The four commonly taught principles are encapsulation, inheritance, polymorphism, and abstraction.
3. What is the difference between a class and an object?
A class is a blueprint, while an object is an instance created from that class.
4. Is Python an object-oriented programming language?
Yes. Python supports object-oriented programming as well as procedural and functional programming styles.
5. Why should students learn Python OOP?
Python OOP helps students develop structured, reusable applications and prepares them to work on larger software projects.
Conclusion
Python OOP concepts help developers create organized, reusable, and maintainable programs. By understanding classes, objects, encapsulation, inheritance, polymorphism, and abstraction, beginners can build a strong foundation for real-world Python development.
Practise the examples, experiment with your own classes, and gradually apply OOP concepts to mini projects.
What to Learn Next
- Python Inheritance with Advanced Examples
- Method Overriding in Python
- Python Modules and Packages
- Build a Python Mini Project Using OOP
Related CCI Blogs
- Python Variables and Data Types
- Python Conditional Statements – if, elif and else
- Python Lists – Store and Manage Multiple Values
Learn Python Programming at CCI Computer Education
Want to improve your programming skills and build practical projects? Join CCI Computer Education, Pudukkottai, to learn programming concepts with hands-on practice and project-based learning.
Explore Python Full Stack Development
Contact CCI Computer Education – Pudukkottai
Call: 98427 97945
Website:
www.ccipudukkottai.com
WhatsApp Channel: Join our WhatsApp Channel
CCI Computer Education – Learn Today, Build Tomorrow.