Object-Oriented Programming
(OOP) in Python
 Exploring Classes, Objects, and Key
 Principles
 Presented by Thejaskumar B R
 Introduction
- Object-Oriented Programming (OOP): A
programming paradigm based on objects.
- Objects: Instances of classes containing data and
methods.
- Classes: Blueprints for creating objects.
Why OOP in Python?
- Organizes code efficiently.
- Encourages reusability and scalability.
 Key OOP Concepts
1. Class: A blueprint for objects.
2. Object: An instance of a class.
3. Encapsulation: Hiding data and methods within a
class.
4. Inheritance: Creating a new class from an existing
class.
5. Polymorphism: Using a single interface for different
data types.
6. Abstraction: Hiding complex implementation details.
 Creating a Class and Object
- Example:
 class Person:
 def __init__(self, name, age):
 self.name = name
 self.age = age
 def greet(self):
 print(f"Hello, my name is {self.name}.")
 person1 = Person("Alice", 25)
 person1.greet()
 Encapsulation
- Definition: Bundling data and methods within a class.
- Example:
 class BankAccount:
 def __init__(self, balance):
 self.__balance = balance
 def deposit(self, amount):
 self.__balance += amount
 def get_balance(self):
 return self.__balance
 account = BankAccount(1000)
 account.deposit(500)
 print(account.get_balance())
 Inheritance
- Definition: Deriving a new class from an existing class.
- Example:
 class Animal:
 def speak(self):
 print("Animal speaks")
 class Dog(Animal):
 def speak(self):
 print("Bark")
 dog = Dog()
 dog.speak()
 Polymorphism
- Definition: Using a single interface for multiple forms.
- Example:
 class Shape:
 def area(self):
 pass
 class Circle(Shape):
 def area(self, radius):
 return 3.14 * radius 2
 shape = Circle()
 print(shape.area(5))
 Abstraction
• - Definition: Hiding complex implementation details and showing only the necessary features.
• - Example:
• ```python
• from abc import ABC, abstractmethod
• class Vehicle(ABC):
• @abstractmethod
• def start(self):
• pass
• class Car(Vehicle):
• def start(self):
• print("Car started")
• car = Car()
• car.start()
• ```
 Summary
- Classes and objects are fundamental in OOP.
- Key principles: Encapsulation, Inheritance,
Polymorphism, and Abstraction.
- OOP in Python promotes clean, modular, and
reusable code.
 Questions?
Let’s discuss and clarify any doubts about OOP in
 Python!
Thank You!