0% found this document useful (0 votes)
6 views41 pages

Python OOP Concepts Explained

Uploaded by

abhinavchitrey
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views41 pages

Python OOP Concepts Explained

Uploaded by

abhinavchitrey
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Academic Session 2025-26

ODD Semester Jul-Dec 2025

UNIVERSITY INSTITUTE OF ENGINEERING


DEPARTMENT OF CSE
PYTHON PROGRAMMING
(24CSP-203)
Unit No. 3 Chapter No. 3.2 Lecture No. 9

Topic : Object-Oriented Programming

Dr. Gitanjali E16525 Assistant Professor


Learning Objectives
1

1. Define and create classes and objects in Python.


2. Understand and implement constructors and
instance/class variables.
3. Apply OOP principles: inheritance, polymorphism,
encapsulation, and abstraction.
4. Differentiate between types of inheritance: single,
multiple, multilevel, hierarchical, hybrid.

Dr. Gitanjali E16525 Assistant Professor


Topics Covered
2

Object-Oriented Programming:
classes, methods, inheritance, and
polymorphism.

Dr. Gitanjali E16525 Assistant Professor


3

Object-Oriented Programming (OOP)


Object Oriented Programming is a fundamental concept
in Python, empowering developers to build modular,
maintainable, and scalable applications. By
understanding the core OOP principles (classes, objects,
inheritance, encapsulation, polymorphism, and
abstraction), programmers can leverage the full
potential of Python OOP capabilities to design elegant
and efficient solutions to complex problems.
Dr. Gitanjali E16525 Assistant Professor
4
Object-Oriented Programming (OOP)
OOPs Concepts in Python
Class in Python
Objects in Python
Polymorphism in Python
Encapsulation in Python
Inheritance in Python
Data Abstraction in Python

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Python Class
A class is a collection of objects. Classes are blueprints for creating
objects. A class defines a set of attributes and methods that the
created objects (instances) can have.
Some points on Python class:
• Classes are created by keyword class.
• Attributes are the variables that belong to a class.
• Attributes are always public and can be accessed using the dot
(.) operator. Example: [Link]

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Creating a Class

Explanation:
class Dog: Defines a class named Dog.
species: A class attribute shared by all instances of the class.
__init__ method: Initializes the name and age attributes when a
new object is created.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Python Objects: An Object is an instance of a Class. It represents a
specific implementation of the class and holds its own data. An
object consists of:
State: It is represented by the attributes and reflects the properties
of an object.
Behavior: It is represented by the methods of an object and reflects
the response of an object to other objects.
Identity: It gives a unique name to an object and enables one object
to interact with other objects.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Creating Object
Explanation:
dog1 = Dog("Buddy", 3): Creates an object of
the Dog class with name as "Buddy" and age
as 3.
[Link]: Accesses the instance attribute
name of the dog1 object.
[Link]: Accesses the class attribute
species of the dog1 object.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Methods (Functions inside a class)
Self Parameter: Self parameter is a reference to the current
instance of the class. It allows us to access the attributes and
methods of the object.
Explanation:
[Link]: Refers to the name attribute of the object (dog1)
calling the method.
[Link](): Calls the bark method on dog1

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Methods (Functions inside a class)

Output:
4
Object-Oriented Programming (OOP)
Methods (Functions inside a class)
__init__ Method is the constructor in
Python, automatically called when a new
object is created. It initializes the
attributes of the class.
__init__: Special method used for
initialization. [Link] and [Link]:
Instance attributes initialized in the
constructor.
Dr. Gitanjali E16525 Assistant Professor
4
Object-Oriented Programming (OOP)
Class Variables
These are the variables that are shared
across all instances of a class. It is defined
at the class level, outside any methods. All
objects of the class share the same value
for a class variable unless explicitly
overridden in an object.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Instance Variables
Variables that are unique to each
instance (object) of a class. These are
defined within the __init__ method or
other instance methods. Each object
maintains its own copy of instance
variables, independent of other objects.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)

Output

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Python Inheritance
Inheritance allows a class (child
class) to acquire properties and
methods of another class (parent
class). It supports hierarchical
Inheritance
classification and promotes code
reuse.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Types of Inheritance:
Single Inheritance: A child class inherits from a single
parent class.
Multiple Inheritance: A child class inherits from more
than one parent class.
Multilevel Inheritance: A child class inherits from a
parent class, which in turn inherits from another class.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Types of Inheritance:
Hierarchical Inheritance: Multiple child classes inherit
from a single parent class.
Hybrid Inheritance: A combination of two or more
types of inheritance.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
1. Single Inheritance
A child class inherits from one parent class.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
2. Multilevel Inheritance
A child class inherits from a class,
which in turn inherits from
another class.
4
Object-Oriented Programming (OOP)
3. Multiple Inheritance
A class inherits from more
than one parent class.
4
Object-Oriented Programming (OOP)
4. Hierarchical Inheritance
Multiple child classes inherit
from a single parent class.
4
Object-Oriented Programming (OOP)
5. Hybrid Inheritance
Combination of two or more
types of inheritance.
4
Object-Oriented Programming (OOP)
Python Polymorphism
Polymorphism allows methods to have the same name
but behave differently based on the object's context. It
can be achieved through method overriding or
overloading.
Types of Polymorphism Many + form
• Compile-Time Polymorphism
• Run-Time Polymorphism
Dr. Gitanjali E16525 Assistant Professor
4
Object-Oriented Programming (OOP)
1. Run-Time Polymorphism:
Demonstrated using method
overriding in the Dog class and its
subclasses. The correct sound
method is invoked at runtime
based on the actual type of the
object in the list.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
2. Compile-Time Polymorphism
Python does not natively support method
overloading. Instead, we use a single
method (add) with default arguments to
handle varying numbers of parameters.
Different behaviors (adding two or three
numbers) are achieved based on how the
method is called.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Python Encapsulation
Encapsulation is the bundling of data (attributes) and
methods (functions) within a class, restricting access to
some components to control interactions.
A class is an example of encapsulation as it encapsulates
all the data that is member functions, variables, etc.

Dr. Gitanjali E16525 Assistant Professor


4
Object-Oriented Programming (OOP)
Types of Encapsulation:
• Public Members: Accessible from anywhere.
• Protected Members: Accessible within the class and
its subclasses.
• Private Members: Accessible only within the class.

Encapsulation
Dr. Gitanjali E16525 Assistant Professor
4
Object-Oriented Programming (OOP)
Data Abstraction
Abstraction hides the internal implementation details while
exposing only the necessary functionality. It helps focus on "what
to do" rather than "how to do it."
Types of Abstraction:
Partial Abstraction: Abstract class contains both abstract and
concrete methods.
Full Abstraction: Abstract class contains only abstract methods
(like interfaces).

Dr. Gitanjali E16525 Assistant Professor


Applications of the Topic
23

• Social Media Platforms


• Vehicle Rental Apps
• Payment Systems

Dr. Gitanjali E16525 Assistant Professor


Summary of the Lecture
24

• Classes and Methods: Objects represent real entities


(e.g., social media users) with attributes and actions.
• Inheritance: Subclasses (e.g., Car, Bike) inherit
common features from a base class (Vehicle) and add
specific behaviors.
• Polymorphism: A single method
(e.g., processPayment()) works differently for different
payment types (credit card, PayPal)

Dr. Gitanjali E16525 Assistant Professor


Next Lecture
7

Topic(s)

• File Handling in Python


• Reading from and writing to text files
• File modes: 'r', 'w', 'a', 'r+'

Dr. Gitanjali – E16525 Assistant Professor


Quiz/ FAQ’s
27

What is a class in Object-Oriented Programming?


A) A variable that stores data
B) A function that performs tasks
C) A blueprint to create objects
D) A type of loop in programming

Dr. Gitanjali E16525 Assistant Professor


Quiz/ FAQ’s
26

What is an object?
A) A function inside a class
B) An instance of a class
C) A data type like integer or string
D) A programming language

Dr. Gitanjali E16525 Assistant Professor


Quiz/ FAQ’s
28

Which of the following best describes a method?


A) A property of an object
B) A variable defined outside a class
C) A function defined inside a class
D) A type of error in programming

Dr. Gitanjali E16525 Assistant Professor


Quiz/ FAQ’s
28

What is inheritance in OOP?


A) A way to hide data from users
B) When a class derives properties from another class
C) When a function calls itself
D) Converting one data type to another

Dr. Gitanjali E16525 Assistant Professor


Quiz/ FAQ’s
28

Which of the following is an example of polymorphism?


A) Different classes sharing the same method name
with different behaviors
B) Variables storing multiple values
C) Hiding the internal details of a class
D) Creating multiple objects from a single class

Dr. Gitanjali E16525 Assistant Professor


References/ Articles/ Videos
29

Suggestive Readings
• Think Python How to Think Like a Computer Scientist (Allen B. Downey)
• Fundamentals of Python First Programs, 2nd Edition (Kenneth A. Lambert)
• Programming and Problem Solving with Python (Ashok Namdev Kamthane, Amit Ashok
Kamthane)

Dr. Gitanjali E16525 Assistant Professor


Faculty-curated videos, NPTEL,
30

Coursera, LinkedIn, or other relevant


learning resources
• [Link]
• [Link]
ing/?srsltid=AfmBOoqZ3wj4YDEuFxoiaxg9EPdgFuFIKzQBcMliP
np-svOa8m6hEELj

Dr. Gitanjali E16525 Assistant Professor


Class-Wise Feedback
29

Dr. Gitanjali – E16525 Assistant Professor


32

Thank You

You might also like