SlideShare a Scribd company logo
3
Most read
Object-Oriented
Programming (OOP)
Concepts in Python
An Introduction
to OOP
Principles with
Python Examples
Introduction to OOP in Python
• - Object-Oriented
Programming (OOP) is a
paradigm using objects and
classes.
• - Helps in structuring code for
reusability and modularity.
• - Python supports OOP along
with procedural and
functional programming.
Key Concepts of OOP
• 1. Class - Blueprint for objects.
• 2. Object - An instance of a class.
• 3. Encapsulation - Restricting access to
data.
• 4. Abstraction - Hiding
implementation details.
• 5. Inheritance - Deriving new classes
from existing ones.
• 6. Polymorphism - Ability to take
multiple forms.
Defining a Class and Creating an Object
• Example:
• ```python
• class Car:
• def __init__(self, brand, model):
• self.brand = brand
• self.model = model
• def display(self):
• print(f'Car: {self.brand}
{self.model}')
• car1 = Car('Toyota', 'Corolla')
• car1.display()
• ```
Encapsulation
• - Protects data by restricting access.
• - Uses private and protected attributes.
• Example:
• ```python
• 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())
• ```
Abstraction
• - Hides unnecessary details and exposes only relevant parts.
• Example:
• ```python
• from abc import ABC, abstractmethod
• class Animal(ABC):
• @abstractmethod
• def make_sound(self):
• pass
• class Dog(Animal):
• def make_sound(self):
• return 'Bark'
• dog = Dog()
• print(dog.make_sound())
• ```
Inheritance
• - Allows a class to inherit properties and methods from another class.
• Example:
• ```python
• class Vehicle:
• def __init__(self, brand):
• self.brand = brand
• def show_brand(self):
• print('Brand:', self.brand)
• class Car(Vehicle):
• def __init__(self, brand, model):
• super().__init__(brand)
• self.model = model
• car = Car('Honda', 'Civic')
• car.show_brand()
• ```
Polymorphism
• - Allows methods to be used interchangeably between different classes.
• Example:
• ```python
• class Bird:
• def sound(self):
• return 'Some bird sound'
• class Sparrow(Bird):
• def sound(self):
• return 'Chirp'
• birds = [Sparrow(), Bird()]
• for bird in birds:
• print(bird.sound())
• ```
Summary
• - Class & Object: Blueprint and instance.
• - Encapsulation: Hiding data for security.
• - Abstraction: Simplifying complex systems.
• - Inheritance: Code reuse via parent-child
relationships.
• - Polymorphism: Flexibility in method usage.
Questions & Discussion
• Any questions? Let's discuss with live coding
examples!

More Related Content

PPTX
Introduction to OOP_Python_Lecture1.pptx
PPTX
OOP_with_Java_Beginner explanation .pptx
PPTX
OOP_Presentation_Enhanced_Updated_wuth new Topics
PPTX
OOP_Presentation_Enhanced_Updated_with new Topics
PPTX
Unit – V Object Oriented Programming in Python.pptx
PPTX
Object Oriented Programming Class and Objects
PPTX
Python_Unit_2 OOPS.pptx
Introduction to OOP_Python_Lecture1.pptx
OOP_with_Java_Beginner explanation .pptx
OOP_Presentation_Enhanced_Updated_wuth new Topics
OOP_Presentation_Enhanced_Updated_with new Topics
Unit – V Object Oriented Programming in Python.pptx
Object Oriented Programming Class and Objects
Python_Unit_2 OOPS.pptx

Similar to OOP Concepts Python with code refrences.pptx (20)

PPTX
Object Oriented Programming in Python.pptx
PDF
PPTX
Object Oriented Concept
PPTX
Introduction to Object Oriented Programming in Python.pptx
PPTX
Classes_python.pptx
PPTX
Python 2. classes- cruciql for students objects1.pptx
PPT
Objective-C for iOS Application Development
PPTX
Presentation 1st
PPTX
Lecture-10_PHP-OOP.pptx
PPTX
Python programming Concepts (Functions, classes and Oops concept
PPTX
Object Oriented Programming.pptx
PPTX
object oriented porgramming using Java programming
PPTX
object oriented porgramming using Java programming
PDF
introductiontooopinpython-171115114144.pdf
PPTX
Introduction to OOP in Python
PPTX
Introduction to C++
PDF
lecture.in ooop object orented programmeg.pdf
PPTX
Presentation 3rd
PPTX
Object oriented programming in C++
PDF
A peek into Python's Metaclass and Bytecode from a Smalltalk User
Object Oriented Programming in Python.pptx
Object Oriented Concept
Introduction to Object Oriented Programming in Python.pptx
Classes_python.pptx
Python 2. classes- cruciql for students objects1.pptx
Objective-C for iOS Application Development
Presentation 1st
Lecture-10_PHP-OOP.pptx
Python programming Concepts (Functions, classes and Oops concept
Object Oriented Programming.pptx
object oriented porgramming using Java programming
object oriented porgramming using Java programming
introductiontooopinpython-171115114144.pdf
Introduction to OOP in Python
Introduction to C++
lecture.in ooop object orented programmeg.pdf
Presentation 3rd
Object oriented programming in C++
A peek into Python's Metaclass and Bytecode from a Smalltalk User
Ad

More from SofiMusic (9)

PPTX
HR_Complete_Presentation best for job_80_Slides.pptx
PPTX
Chapter 11 Computer Networks I.this the certain reasonpptx
PPTX
wireandwireless comunication in IOT devices.pptx
PPTX
Sensors_in_IoT.pptx Inter net of things best Explanatiom
PPTX
Chemstudy.pptx Chem.py is the best Solution for Chemistry problems
PPTX
SQL.pptx
PPTX
2022-48Advance Algo Analysis 3rd Assignment.pptx
PPTX
Advance analysis of algorithm.pptx
PPTX
Insertion sort presentation.pptx
HR_Complete_Presentation best for job_80_Slides.pptx
Chapter 11 Computer Networks I.this the certain reasonpptx
wireandwireless comunication in IOT devices.pptx
Sensors_in_IoT.pptx Inter net of things best Explanatiom
Chemstudy.pptx Chem.py is the best Solution for Chemistry problems
SQL.pptx
2022-48Advance Algo Analysis 3rd Assignment.pptx
Advance analysis of algorithm.pptx
Insertion sort presentation.pptx
Ad

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Pharma ospi slides which help in ospi learning
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
English Language Teaching from Post-.pdf
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Cell Structure & Organelles in detailed.
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
From loneliness to social connection charting
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PDF
Module 3: Health Systems Tutorial Slides S2 2025
102 student loan defaulters named and shamed – Is someone you know on the list?
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Pharma ospi slides which help in ospi learning
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Anesthesia in Laparoscopic Surgery in India
English Language Teaching from Post-.pdf
UPPER GASTRO INTESTINAL DISORDER.docx
Abdominal Access Techniques with Prof. Dr. R K Mishra
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Cell Structure & Organelles in detailed.
Introduction and Scope of Bichemistry.pptx
From loneliness to social connection charting
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Open Quiz Monsoon Mind Game Final Set.pptx
Module 3: Health Systems Tutorial Slides S2 2025

OOP Concepts Python with code refrences.pptx

  • 1. Object-Oriented Programming (OOP) Concepts in Python An Introduction to OOP Principles with Python Examples
  • 2. Introduction to OOP in Python • - Object-Oriented Programming (OOP) is a paradigm using objects and classes. • - Helps in structuring code for reusability and modularity. • - Python supports OOP along with procedural and functional programming.
  • 3. Key Concepts of OOP • 1. Class - Blueprint for objects. • 2. Object - An instance of a class. • 3. Encapsulation - Restricting access to data. • 4. Abstraction - Hiding implementation details. • 5. Inheritance - Deriving new classes from existing ones. • 6. Polymorphism - Ability to take multiple forms.
  • 4. Defining a Class and Creating an Object • Example: • ```python • class Car: • def __init__(self, brand, model): • self.brand = brand • self.model = model • def display(self): • print(f'Car: {self.brand} {self.model}') • car1 = Car('Toyota', 'Corolla') • car1.display() • ```
  • 5. Encapsulation • - Protects data by restricting access. • - Uses private and protected attributes. • Example: • ```python • 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()) • ```
  • 6. Abstraction • - Hides unnecessary details and exposes only relevant parts. • Example: • ```python • from abc import ABC, abstractmethod • class Animal(ABC): • @abstractmethod • def make_sound(self): • pass • class Dog(Animal): • def make_sound(self): • return 'Bark' • dog = Dog() • print(dog.make_sound()) • ```
  • 7. Inheritance • - Allows a class to inherit properties and methods from another class. • Example: • ```python • class Vehicle: • def __init__(self, brand): • self.brand = brand • def show_brand(self): • print('Brand:', self.brand) • class Car(Vehicle): • def __init__(self, brand, model): • super().__init__(brand) • self.model = model • car = Car('Honda', 'Civic') • car.show_brand() • ```
  • 8. Polymorphism • - Allows methods to be used interchangeably between different classes. • Example: • ```python • class Bird: • def sound(self): • return 'Some bird sound' • class Sparrow(Bird): • def sound(self): • return 'Chirp' • birds = [Sparrow(), Bird()] • for bird in birds: • print(bird.sound()) • ```
  • 9. Summary • - Class & Object: Blueprint and instance. • - Encapsulation: Hiding data for security. • - Abstraction: Simplifying complex systems. • - Inheritance: Code reuse via parent-child relationships. • - Polymorphism: Flexibility in method usage.
  • 10. Questions & Discussion • Any questions? Let's discuss with live coding examples!