SlideShare a Scribd company logo
Python – Object Oriented Programming
by Raghunath Akula
Classes & Objects
 Class serves as the primary means of abstraction in Object-Oriented
programing.
 A class provides a set of behaviors in the form of member_functions /
methods, with implementation that are common to all instance.
 In class, the state information for each instance is represented in the
form of Attributes / Data members.
 Instances are objects that are created which follow the definition given
inside of the class.
 No separate class interface definition.
class MyVector:
def __init__(self, x, y):
self . x = x
self . y = y
def __add__(self, param2):
return MyVector(self.x + param2.x, self.y + param2.y)
Obj1 = MyVector(1, 2) “Object initiation for MyVector class.”
Access Specifiers
 Python provides a number of access modifiers to help you set the level
of access for attributes and methods.
 Private - 2 leading under-scores in its name, but none at the end. Can’t
be accessed outside of class
 Built-in – Methods or attributes having 2 underscores at the beginning
and the end.
 Doesn’t support ‘protected’. Subclasses would be unable to access these
private data either.
Garbage Collector
 Python has automatic garbage collection.
 Will automatically detect when all of the references to a piece of
memory have gone out of scope. Automatically frees that memory.
 There’s also no Destructor method for classes
Methods
 Define a method in a class by including function definitions within the
scope of the class block
 There must be a special first argument self in all of method definitions
which gets bound to the calling instance
 There is usually a special method called __init__ in most classes
class MyVector:
count = 0 “Class attribute”
def __init__(self, x, y):
self . x = x
self . y = y
def __add__(self, param2):
return MyVector(self.x + param2.x, self.y + param2.y)
def displayCount(self):
count = self.x + self.y
return count
Obj1 = MyVector(1, 2) “Object initiation for MyVector class.”
print Obj1.displayCount() “Calling displayCount method.”
Constructor ( __init__ )
 Serves as a constructor for a class.
 The arguments passed to the class are given to its __init__() method
def __init__(self, x, y):
self . x = x
self . y = y
self
 The first argument of every method is a reference to the current instance of
the class
 Parameter object self refers to current object being created, similar to
keyword this in Java
 Although self explicitly mentioned when defining the method, not mandatory
included while calling the method. Self parameter is passed automatically by
python.
Attributes
Two Kinds of Attributes:
(1)Data Attributes
Owned by particular instance of a class.
Each instance has its own value for it.
(2)Class Attributes
All instance inside class share the same value for it.
Similar to static variables or class-wide constants.
“Example: Data Attributes”
class MyVector:
def __init__(self, x, y):
self . x = x
self . y = y
“Example: Class Attributes”
class MyVector:
count = 0 “static variable”
def displayCount(self):
count = self.x + self.y
return count
Inheritance
 A class can extend the definition of another class
 Allows to use methods and attributes already defined in the previous
classes.
 To define a subclass, put the name of the superclass in parentheses
“(…)”.
 Python has no ‘extends’ keyword like Java. Python supports multiple
inheritance.
“Extending MyVector class”
class SubVector (MyVector):
def __init__(self, sub_x, sub_y):
self . x = sub_x
self . y = sub_y
def displayCount(self):
count = self.x + self.y
return count
Method Overriding
 Overriding is a very important part of OOP. It has the ability of a
class to change the implementation of a method provided by one of its
ancestors.
 Python inheritance works through implicit delegation – when the object
cannot satisfy a request, it forward request to its ancestors.
“Parent Class”
class MyVector:
def __init__(self, x, y):
self . x = x
self . y = y
def displayCount(self):
return self.x + self.y
“Child Class”
class SubVector (MyVector):
def displayCount(self): “Overriding dispalyCount method”
return self.x + 10
Thank you!!

More Related Content

PPTX
Chapter 05 classes and objects
Praveen M Jigajinni
 
PDF
Object oriented approach in python programming
Srinivas Narasegouda
 
PPTX
Object oriented programming in python
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
PPTX
Unit 1 OOSE
ChhayaShelake
 
PPTX
Class, object and inheritance in python
Santosh Verma
 
PPT
Oops ppt
abhayjuneja
 
ODP
Python Modules
Nitin Reddy Katkam
 
Chapter 05 classes and objects
Praveen M Jigajinni
 
Object oriented approach in python programming
Srinivas Narasegouda
 
Object oriented programming in python
baabtra.com - No. 1 supplier of quality freshers
 
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
Unit 1 OOSE
ChhayaShelake
 
Class, object and inheritance in python
Santosh Verma
 
Oops ppt
abhayjuneja
 
Python Modules
Nitin Reddy Katkam
 

What's hot (20)

PPTX
Python OOPs
Binay Kumar Ray
 
PDF
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
PPTX
Abstract class and Interface
Haris Bin Zahid
 
PDF
Object-oriented Programming-with C#
Doncho Minkov
 
PPTX
Python-Encapsulation.pptx
Karudaiyar Ganapathy
 
PPTX
Access Modifier.pptx
Margaret Mary
 
PPTX
OOP concepts -in-Python programming language
SmritiSharma901052
 
PPTX
Object oriented programming with python
Arslan Arshad
 
PPTX
Operator overloading
Ramish Suleman
 
PPTX
Object oriented programming
Amit Soni (CTFL)
 
PPTX
C# classes objects
Dr.Neeraj Kumar Pandey
 
PPTX
virtual function
VENNILAV6
 
PDF
Generics and collections in Java
Gurpreet singh
 
PPTX
Java string handling
Salman Khan
 
PPTX
Java constructors
QUONTRASOLUTIONS
 
PPTX
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
PDF
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Maulik Borsaniya
 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
 
Python OOPs
Binay Kumar Ray
 
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Abstract class and Interface
Haris Bin Zahid
 
Object-oriented Programming-with C#
Doncho Minkov
 
Python-Encapsulation.pptx
Karudaiyar Ganapathy
 
Access Modifier.pptx
Margaret Mary
 
OOP concepts -in-Python programming language
SmritiSharma901052
 
Object oriented programming with python
Arslan Arshad
 
Operator overloading
Ramish Suleman
 
Object oriented programming
Amit Soni (CTFL)
 
C# classes objects
Dr.Neeraj Kumar Pandey
 
virtual function
VENNILAV6
 
Generics and collections in Java
Gurpreet singh
 
Java string handling
Salman Khan
 
Java constructors
QUONTRASOLUTIONS
 
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Maulik Borsaniya
 
Looping Statements and Control Statements in Python
PriyankaC44
 
Ad

Similar to Python – Object Oriented Programming (20)

PPT
Introduction to Python - Part Three
amiable_indian
 
PPT
Python3
Ruchika Sinha
 
PPT
Lecture topic - Python class lecture.ppt
Reji K Dhaman
 
PPT
Lecture on Python class -lecture123456.ppt
Reji K Dhaman
 
PDF
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Mohammad Reza Kamalifard
 
PDF
Dive into Python Class
Jim Yeh
 
PPT
Python session 7 by Shan
Navaneethan Naveen
 
PPTX
python.pptx
Dhanushrajucm
 
PDF
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
Mohammad Reza Kamalifard
 
PPTX
Python_Object_Oriented_Programming.pptx
Koteswari Kasireddy
 
PDF
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
SudhanshiBakre1
 
PDF
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
SudhanshiBakre1
 
PPTX
classes and objects of python object oriented
VineelaThonduri
 
PDF
Python - object oriented
Learnbay Datascience
 
PPTX
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
NagarathnaRajur2
 
PPT
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
PDF
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
PPTX
Basic_concepts_of_OOPS_in_Python.pptx
santoshkumar811204
 
PPT
Class and object in C++
rprajat007
 
Introduction to Python - Part Three
amiable_indian
 
Python3
Ruchika Sinha
 
Lecture topic - Python class lecture.ppt
Reji K Dhaman
 
Lecture on Python class -lecture123456.ppt
Reji K Dhaman
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Mohammad Reza Kamalifard
 
Dive into Python Class
Jim Yeh
 
Python session 7 by Shan
Navaneethan Naveen
 
python.pptx
Dhanushrajucm
 
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
Mohammad Reza Kamalifard
 
Python_Object_Oriented_Programming.pptx
Koteswari Kasireddy
 
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
SudhanshiBakre1
 
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
SudhanshiBakre1
 
classes and objects of python object oriented
VineelaThonduri
 
Python - object oriented
Learnbay Datascience
 
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
NagarathnaRajur2
 
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
Basic_concepts_of_OOPS_in_Python.pptx
santoshkumar811204
 
Class and object in C++
rprajat007
 
Ad

Recently uploaded (20)

PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Software Development Company | KodekX
KodekX
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 

Python – Object Oriented Programming

  • 1. Python – Object Oriented Programming by Raghunath Akula
  • 2. Classes & Objects  Class serves as the primary means of abstraction in Object-Oriented programing.  A class provides a set of behaviors in the form of member_functions / methods, with implementation that are common to all instance.  In class, the state information for each instance is represented in the form of Attributes / Data members.  Instances are objects that are created which follow the definition given inside of the class.  No separate class interface definition. class MyVector: def __init__(self, x, y): self . x = x self . y = y def __add__(self, param2): return MyVector(self.x + param2.x, self.y + param2.y) Obj1 = MyVector(1, 2) “Object initiation for MyVector class.”
  • 3. Access Specifiers  Python provides a number of access modifiers to help you set the level of access for attributes and methods.  Private - 2 leading under-scores in its name, but none at the end. Can’t be accessed outside of class  Built-in – Methods or attributes having 2 underscores at the beginning and the end.  Doesn’t support ‘protected’. Subclasses would be unable to access these private data either. Garbage Collector  Python has automatic garbage collection.  Will automatically detect when all of the references to a piece of memory have gone out of scope. Automatically frees that memory.  There’s also no Destructor method for classes
  • 4. Methods  Define a method in a class by including function definitions within the scope of the class block  There must be a special first argument self in all of method definitions which gets bound to the calling instance  There is usually a special method called __init__ in most classes class MyVector: count = 0 “Class attribute” def __init__(self, x, y): self . x = x self . y = y def __add__(self, param2): return MyVector(self.x + param2.x, self.y + param2.y) def displayCount(self): count = self.x + self.y return count Obj1 = MyVector(1, 2) “Object initiation for MyVector class.” print Obj1.displayCount() “Calling displayCount method.”
  • 5. Constructor ( __init__ )  Serves as a constructor for a class.  The arguments passed to the class are given to its __init__() method def __init__(self, x, y): self . x = x self . y = y self  The first argument of every method is a reference to the current instance of the class  Parameter object self refers to current object being created, similar to keyword this in Java  Although self explicitly mentioned when defining the method, not mandatory included while calling the method. Self parameter is passed automatically by python.
  • 6. Attributes Two Kinds of Attributes: (1)Data Attributes Owned by particular instance of a class. Each instance has its own value for it. (2)Class Attributes All instance inside class share the same value for it. Similar to static variables or class-wide constants. “Example: Data Attributes” class MyVector: def __init__(self, x, y): self . x = x self . y = y “Example: Class Attributes” class MyVector: count = 0 “static variable” def displayCount(self): count = self.x + self.y return count
  • 7. Inheritance  A class can extend the definition of another class  Allows to use methods and attributes already defined in the previous classes.  To define a subclass, put the name of the superclass in parentheses “(…)”.  Python has no ‘extends’ keyword like Java. Python supports multiple inheritance. “Extending MyVector class” class SubVector (MyVector): def __init__(self, sub_x, sub_y): self . x = sub_x self . y = sub_y def displayCount(self): count = self.x + self.y return count
  • 8. Method Overriding  Overriding is a very important part of OOP. It has the ability of a class to change the implementation of a method provided by one of its ancestors.  Python inheritance works through implicit delegation – when the object cannot satisfy a request, it forward request to its ancestors. “Parent Class” class MyVector: def __init__(self, x, y): self . x = x self . y = y def displayCount(self): return self.x + self.y “Child Class” class SubVector (MyVector): def displayCount(self): “Overriding dispalyCount method” return self.x + 10