Sitemap
D Naresh

D Naresh

Object-Oriented Programming (OOPs) in Python

Python Made Easy - (Article 11) Telugu Explanation

4 min readOct 31, 2025

--

Press enter or click to view image in full size

1. What is Object-Oriented Programming?

OOPs ante “Object-Oriented Programming”.
Idi manam program ni objects and classes form lo divide chesi organize cheyyadam.

Simple ga cheppali ante:
Instead of writing code randomly, we create blueprints (classes) and use them to build objects (real things).

1.Real-Life Example (Simple Understanding)

🪑 Think about a chair factory.

  • Factory lo “Chair” ane design untundi (size, color, material…).
    → This design = Class
  • Aa design base chesukoni create chesina prathi chair = Object

So, Class = Blueprint / Design
Object = Real thing created from that design

2. Why OOP?

Press enter or click to view image in full size

OOPs use cheyyalsina main reason:

  • Code easy ga organize cheyyachu.
  • Reuse cheyyachu (once class create chesaka, multiple times use cheyyachu).
  • Errors reduce avutayi.
  • Large projects easy ga maintain cheyyachu.

3. Class and Object in Python

Press enter or click to view image in full size

Syntax of Class

class ClassName:
# properties (variables)
# methods (functions)

Example:

class Car:
def __init__(self, brand, color):
self.brand = brand
self.color = color
    def show_details(self):
print("Brand:", self.brand)
print("Color:", self.color)
# Creating objects
car1 = Car("BMW", "Black")
car2 = Car("Audi", "White")
# Calling methods
car1.show_details()
car2.show_details()

Output:

Brand: BMW
Color: Black
Brand: Audi
Color: White

4. Explanation of the Example

  • class Car: → Blueprint create chestunnam.
  • init() → Special function called constructor, object create ayyaka automatically run avuthundi.
  • self → Current object ni refer chestundi (like “this” in other languages).
  • car1, car2 → Two objects created from the same class.
  • show_details() → Class lo define chesina method (function inside class).

5. Constructor in Python

Constructor ante init() method.
Object create ayyaka automatically call avuthundi.
Manam initial values ivvadam kosam use chestam.

class Student:
def __init__(self, name, age):
self.name = name
self.age = age
s1 = Student("Naresh", 25)
print(s1.name)
print(s1.age)

Output:

Naresh
25

6. self Keyword

self ante current object reference.
Without self, Python ki teliyadu e variable / method ye object ki sambandham ani.

Get D Naresh’s stories in your inbox

Join Medium for free to get updates from this writer.

Example:

class Example:
def greet(self):
print("Hello from", self)

Idi run chesthe self actual memory location chupistundi.

7. Types of Methods

  1. Instance Method — Use self, access instance variables.
  2. Class Method — Use @classmethod and cls.
  3. Static Method — Use @staticmethod, no self or cls.

Example:

class Demo:
company = "Infosys"
    def __init__(self, name):
self.name = name
def show(self): # Instance Method
print("Employee:", self.name)
@classmethod
def get_company(cls): # Class Method
print("Company:", cls.company)
@staticmethod
def greet(): # Static Method
print("Welcome to the Company!")
d = Demo("Naresh")
d.show()
Demo.get_company()
Demo.greet()

Output:

Employee: Naresh
Company: Infosys
Welcome to the Company!

8. Four Pillars of OOPs

OOPs lo 4 main pillars untayi

Press enter or click to view image in full size

9. Inheritance Example

Press enter or click to view image in full size
class Parent:
def show_parent(self):
print("I am the Parent")
class Child(Parent):
def show_child(self):
print("I am the Child")
obj = Child()
obj.show_parent()
obj.show_child()

Output:

I am the Parent
I am the Child

Explanation:
Child class → Parent class methods ni use chesindi.

10. Polymorphism Example

Press enter or click to view image in full size
class Bird:
def sound(self):
print("Some generic bird sound")
class Sparrow(Bird):
def sound(self):
print("Chirp Chirp")
class Crow(Bird):
def sound(self):
print("Caw Caw")
for bird in (Sparrow(), Crow()):
bird.sound()

Output:

Chirp Chirp
Caw Caw

11. Encapsulation Example

Press enter or click to view image in full size
class Account:
def __init__(self, balance):
self.__balance = balance # private variable
    def get_balance(self):
return self.__balance
a = Account(5000)
print(a.get_balance())

Output:

5000

__balance private variable, direct ga access cheyyalem → encapsulation.

12. Abstraction Example

Press enter or click to view image in full size
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
class Circle(Shape):
def area(self):
print("Area of circle calculated here")
obj = Circle()
obj.area()

Output:

Area of circle calculated here

Abstract class lo abstract methods untayi → compulsory override cheyyali.

13. Summary / Key Takeaways

  • OOP → Object-Oriented Programming
  • Class = Design, Object = Real-world entity
  • __init__() → constructor
  • self → current object reference
  • 4 pillars → Encapsulation, Abstraction, Inheritance, Polymorphism
  • Code easy ga reuse cheyyachu, organize cheyyachu

14. Practice Questions

1️.Create a class Student with name, age and marks.

  • Method to display details.

2️.Create a BankAccount class with deposit and withdraw methods.

3️.Create a parent class Animal, child class Dog → method overriding practice.

4️.Create a class with @staticmethod and @classmethod examples.

Previous & Next

Next Article: 👉 12. File Handling in Python

Previous Article:👉 10. Strings & String Operations

--