0% found this document useful (0 votes)
2 views28 pages

OOP in Python Modifying

This document provides an introduction to Object-Oriented Programming (OOP) in Python, covering basic concepts, principles, and real-world applications. It explains key terms such as classes, objects, encapsulation, inheritance, polymorphism, and abstraction, along with their benefits and drawbacks. The document emphasizes the importance of OOP in organizing code and modeling real-world scenarios.

Uploaded by

meena
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)
2 views28 pages

OOP in Python Modifying

This document provides an introduction to Object-Oriented Programming (OOP) in Python, covering basic concepts, principles, and real-world applications. It explains key terms such as classes, objects, encapsulation, inheritance, polymorphism, and abstraction, along with their benefits and drawbacks. The document emphasizes the importance of OOP in organizing code and modeling real-world scenarios.

Uploaded by

meena
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
You are on page 1/ 28

Title Slide

• Introduction to Object-Oriented Programming


(OOP) in Python
Overview
• What you will learn:
• - Basic OOP concepts
• - Real-world examples
What is OOP?
• Object-Oriented Programming (OOP) is a way
of writing programs using objects.
• It helps us organize code, reuse it, and make it
easier to understand and update.
• Python supports OOP through classes and
objects.
Why OOP?
• Benefits include modularity, reusability,
abstraction, and ease of maintenance.
Real-Life Example
• Think of a 'Car':
• Properties – color, model
• Behaviors – start(), stop()
Four Main Principles
• 1. Encapsulation
• 2. Inheritance
• 3. Polymorphism
• 4. Abstraction
What is a Class?
• A class is a blueprint for creating objects.
Syntax of a Class
• class Student:
• def __init__(self, name):
• self.name = name
What is an Object?
• An object is an instance of a class.
Creating Objects
• s1 = Student('Rahul')
• print(s1.name)
__init__ Method (constructor)
• Used to initialize object attributes at creation.
self
Encapsulation
• Combining data and methods into a single
unit.
Encapsulation Example
• class Bank:
• def __init__(self):
• self.__balance = 0
Inheritance
• Allows one class to inherit properties of
another class.
Single Inheritance
• One child class inherits from one parent class.
Multilevel Inheritance
• A -> B -> C
• Each level inherits from its predecessor.
Multiple Inheritance
• A class inherits from multiple parent classes.
super() Keyword
• Used to call parent class methods in child
class.
Method Overriding
• Redefining parent class methods in child class.
Polymorphism
• Same function name, different behaviors
based on context.
Polymorphism Example
Abstraction
• Hides complex details and shows only
necessary parts.
Example of Abstraction
• from abc import ABC, abstractmethod
• class Shape(ABC):
• @abstractmethod
• def area(self): pass
Advantages of OOP
• - Organized code
• - Reusability
• - Real-world modeling
Disadvantages of OOP
• - Steep learning curve
• - Slightly slower performance
Real-World Applications
• Used in games, GUIs, simulations, business
apps
Summary
Term Meaning
Class Blueprint for objects
Object Instance of a class
__init__ Constructor to initialize objects
self Refers to the current object
Encapsulation Hides internal details
Inheritance Reuse code from other classes
Polymorphism One function, many forms
Abstraction Hides complex details, shows essentials

You might also like