SlideShare a Scribd company logo
Problem solving with python programming OOP's Concept
School of Computer Science & Artificial Intelligence
Bura Vijay Kumar
Assistant Professor,
Email : b.vijaykumar@sru.edu.in
2
Course
PROBLEM SOLVING USING PYTHON
PROGRAMMING
3
Unit-V
Overview
Object-Oriented Programming:
Introduction to Object Oriented Programming;
Class
Object
Encapsulation;
Inheritance;
Polymorphism
Abstraction
Object Oriented Programming :
● Object Oriented Programming can be defined as a programming model which is based
upon the concept of objects.
● Objects contain data in the form of attributes and code in the form of methods. In object
oriented programming, computer programs are designed using the concept of objects that
interact with real world.
● Languages used in Object Oriented Programming:
Java, C++, C#, Python, PHP, JavaScript, Ruby, Perl, Objective-C, Dart, Swift, Scala.
Advantages of Object Oriented Programming
Object Oriented Programming Concepts
● Procedural Vs Object Oriented
Object Oriented Programming :
● It supports All OOP's concepts
● In java everything is Object which has some data and behavior.
○ Object
○ Class
○ Abstraction
○ Encapsulation
○ Inheritance
○ Polymorphism
Object Oriented Programming :
Object:
● Object is an Real world Entity
● Instance of a class is called an Object.
● It has properties (attributes)
● Task performed (operations)
Example:
Human
Attributes/Properties Tasks(Operations)
Name walk()
Color run()
Height read()
Etc.. Etc..
Object Oriented Programming :
Class:
● Class is a blue print that object follows
● A Class consist of ‘N’ Number of Object.
● Class is a collection of objects and there attributes, operations and there
relationships
Example:
Student
Variables/Properties Tasks(Operations)
Name read()
Roll No write()
DoJ play()
Etc.. Etc..
Object Oriented Programming :
Class: Example
Abstraction
● Showing only essential parts, hiding the implementation details is
called Abstraction.
Example:
Google play Store
Android Applications
.apk files
.exe files
Encapsulation
● Binding Variables and Methods under single Entity
or
● Wrapping of data into Single Unit is called Encapsulation.
Example:
Inheritance
● Acquiring the properties of one class to another class is called
Inheritance.
Example:
Types of Inheritance:
 Single Inheritance
 Multiple Inheritance
 Multi-level Inheritance
 Hierarchical Inheritance
Polymorphism
● Performing same task in different ways is called Polymorphism.
● The ability of an object to take many forms.
Example:
Polymorphism can be achieved by
● Method Overloading – Compile Time
● Method Overriding – Run Time
Python Classes and Objects
Python Classes/Objects
● Python is an object oriented programming language.
● Almost everything in Python is an object, with its properties and methods.
● A Class is like an object constructor, or a "blueprint" for creating objects.
Create a Class
● To create a class, use the keyword class:
Example:
Python Classes and Objects
Python Classes/Objects
Create Object
● Now we can use the class named MyClass to create objects:
Example 1:
● Create an object named p1, and print the value of x:
● Example 2:
Python Classes and Objects
Python Classes and Objects
Python Classes and Objects
The __init__() Function
● Use the __init__() function to assign values to object properties, or other operations
that are necessary to do when the object is being created.
● All classes have a function called __init__(), which is always executed when the class
is being initiated.
Example :
Note: The __init__() function is called automatically every time the class is being used to create a new object.
Python Classes and Objects
Object Methods
● Objects can also contain methods. Methods in objects are functions that belong to
the object.
● Let us create a method in the Person class:
Example
● Insert a function that prints a greeting, and execute it on the p1 object:
Python Classes and Objects
The self Parameter
● The self parameter is a reference to the current instance of the class, and is used to
access variables that belongs to the class.
● It does not have to be named self , you can call it whatever you like, but it has to be
the first parameter of any function in the class:
Example:
● Use the words my_object and abc instead of self :
Python Classes and Objects
Modify Object Properties
● You can modify properties on objects like this:
Example:
Python Classes and Objects
Delete Object Properties
● You can delete properties on objects by using the del keyword:
Example:
● Delete the age property from the p1 object:
Python Classes and Objects
The pass Statement
● class definitions cannot be empty, but if you for some reason have a class definition
with no content, put in the pass statement to avoid getting an error.
Python Classes and Objects
Python Inheritance
● Inheritance allows us to define a class that inherits all the methods and properties
from another class.
● Parent class is the class being inherited from, also called base class.
● Child class is the class that inherits from another class, also called derived class.
Python Inheritance
In Single Inheritance one class extends another class
(one class only).
Python Inheritance
● In Multilevel Inheritance, one class can inherit from a derived class.
Python Inheritance
● In Hierarchical Inheritance, one class is inherited by many sub classes.
Python Inheritance
● In Multiple Inheritance, one class extending more than one class.
Python Inheritance
Create a Parent Class
● Any class can be a parent class, so the syntax is the same as creating any other class:
Example
● Create a class named Person, with firstname and lastname properties, and
a printname method:
Python Inheritance
Create a Child Class
● To create a class that inherits the functionality from another class, send the parent
class as a parameter when creating the child class:
Example
● Create a class named Student, which will inherit the properties and methods from
the Person class:
class Student(Person):
pass
Note: Use the pass keyword when you do not want to add any other properties or
methods to the class.
● Now the Student class has the same properties and methods as the Person class.
Python Inheritance
Create a Child Class
Example
● Use the Student class to create an object, and then execute the printname method:
Python Inheritance
Use the super() Function
● Python also has a super() function that will make the child class inherit all the
methods and properties from its parent:
class Student(Person):
def __init__(self, fname, lname):
super().__init__(fname, lname)
Python Encapsulation
Python Polymorphism
Python Abstraction
What you learnt in
this session
Summary of the topic
Specific topics:
● Sub topic 1
● Sub topic 2
If any questions
Question 1
● Option 1
● Option 2
● Option 3
● Option 4
● Option 1
● Option 2
● Option 3
● Option 4
Question 2

More Related Content

Similar to Problem solving with python programming OOP's Concept (20)

software construction and development week 3 Python lists, tuples, dictionari...
software construction and development week 3 Python lists, tuples, dictionari...software construction and development week 3 Python lists, tuples, dictionari...
software construction and development week 3 Python lists, tuples, dictionari...
MuhammadBilalAjmal2
 
CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONCLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHON
Lalitkumar_98
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
KALAISELVI P
 
CLTL python course: Object Oriented Programming (1/3)
CLTL python course: Object Oriented Programming (1/3)CLTL python course: Object Oriented Programming (1/3)
CLTL python course: Object Oriented Programming (1/3)
Rubén Izquierdo Beviá
 
Object oriented Programning Lanuagues in text format.
Object oriented Programning Lanuagues in text format.Object oriented Programning Lanuagues in text format.
Object oriented Programning Lanuagues in text format.
SravaniSravani53
 
PYTHON OBJECT-ORIENTED PROGRAMMING.pptx
PYTHON  OBJECT-ORIENTED PROGRAMMING.pptxPYTHON  OBJECT-ORIENTED PROGRAMMING.pptx
PYTHON OBJECT-ORIENTED PROGRAMMING.pptx
hpearl130
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)object oriented programming(PYTHON)
object oriented programming(PYTHON)
Jyoti shukla
 
oops-in-python-240412044200-2d5c6552.pptx
oops-in-python-240412044200-2d5c6552.pptxoops-in-python-240412044200-2d5c6552.pptx
oops-in-python-240412044200-2d5c6552.pptx
anilvarsha1
 
inheritance in python with full detail.ppt
inheritance in python with full detail.pptinheritance in python with full detail.ppt
inheritance in python with full detail.ppt
ssuser7b0a4d
 
Object Oriented Programming in Python.pptx
Object Oriented Programming in Python.pptxObject Oriented Programming in Python.pptx
Object Oriented Programming in Python.pptx
grpvasundhara1993
 
Python-Classes.pptx
Python-Classes.pptxPython-Classes.pptx
Python-Classes.pptx
Karudaiyar Ganapathy
 
Inheritance
InheritanceInheritance
Inheritance
JayanthiNeelampalli
 
Unit – V Object Oriented Programming in Python.pptx
Unit – V Object Oriented Programming in Python.pptxUnit – V Object Oriented Programming in Python.pptx
Unit – V Object Oriented Programming in Python.pptx
YugandharaNalavade
 
OOP Concepts Python with code refrences.pptx
OOP Concepts Python with code refrences.pptxOOP Concepts Python with code refrences.pptx
OOP Concepts Python with code refrences.pptx
SofiMusic
 
9-_Object_Oriented_Programming_Using_Python 1.pptx
9-_Object_Oriented_Programming_Using_Python 1.pptx9-_Object_Oriented_Programming_Using_Python 1.pptx
9-_Object_Oriented_Programming_Using_Python 1.pptx
Lahari42
 
Presentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptxPresentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptx
MuhammadChala
 
Introduction to OOP_Python_Lecture1.pptx
Introduction to OOP_Python_Lecture1.pptxIntroduction to OOP_Python_Lecture1.pptx
Introduction to OOP_Python_Lecture1.pptx
cpics
 
python note.pdf
python note.pdfpython note.pdf
python note.pdf
Nagendra504676
 
Object oriented Programming in Python.pptx
Object oriented Programming in Python.pptxObject oriented Programming in Python.pptx
Object oriented Programming in Python.pptx
SHAIKIRFAN715544
 
Python advance
Python advancePython advance
Python advance
Mukul Kirti Verma
 
software construction and development week 3 Python lists, tuples, dictionari...
software construction and development week 3 Python lists, tuples, dictionari...software construction and development week 3 Python lists, tuples, dictionari...
software construction and development week 3 Python lists, tuples, dictionari...
MuhammadBilalAjmal2
 
CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONCLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHON
Lalitkumar_98
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
KALAISELVI P
 
CLTL python course: Object Oriented Programming (1/3)
CLTL python course: Object Oriented Programming (1/3)CLTL python course: Object Oriented Programming (1/3)
CLTL python course: Object Oriented Programming (1/3)
Rubén Izquierdo Beviá
 
Object oriented Programning Lanuagues in text format.
Object oriented Programning Lanuagues in text format.Object oriented Programning Lanuagues in text format.
Object oriented Programning Lanuagues in text format.
SravaniSravani53
 
PYTHON OBJECT-ORIENTED PROGRAMMING.pptx
PYTHON  OBJECT-ORIENTED PROGRAMMING.pptxPYTHON  OBJECT-ORIENTED PROGRAMMING.pptx
PYTHON OBJECT-ORIENTED PROGRAMMING.pptx
hpearl130
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)object oriented programming(PYTHON)
object oriented programming(PYTHON)
Jyoti shukla
 
oops-in-python-240412044200-2d5c6552.pptx
oops-in-python-240412044200-2d5c6552.pptxoops-in-python-240412044200-2d5c6552.pptx
oops-in-python-240412044200-2d5c6552.pptx
anilvarsha1
 
inheritance in python with full detail.ppt
inheritance in python with full detail.pptinheritance in python with full detail.ppt
inheritance in python with full detail.ppt
ssuser7b0a4d
 
Object Oriented Programming in Python.pptx
Object Oriented Programming in Python.pptxObject Oriented Programming in Python.pptx
Object Oriented Programming in Python.pptx
grpvasundhara1993
 
Unit – V Object Oriented Programming in Python.pptx
Unit – V Object Oriented Programming in Python.pptxUnit – V Object Oriented Programming in Python.pptx
Unit – V Object Oriented Programming in Python.pptx
YugandharaNalavade
 
OOP Concepts Python with code refrences.pptx
OOP Concepts Python with code refrences.pptxOOP Concepts Python with code refrences.pptx
OOP Concepts Python with code refrences.pptx
SofiMusic
 
9-_Object_Oriented_Programming_Using_Python 1.pptx
9-_Object_Oriented_Programming_Using_Python 1.pptx9-_Object_Oriented_Programming_Using_Python 1.pptx
9-_Object_Oriented_Programming_Using_Python 1.pptx
Lahari42
 
Presentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptxPresentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptx
MuhammadChala
 
Introduction to OOP_Python_Lecture1.pptx
Introduction to OOP_Python_Lecture1.pptxIntroduction to OOP_Python_Lecture1.pptx
Introduction to OOP_Python_Lecture1.pptx
cpics
 
Object oriented Programming in Python.pptx
Object oriented Programming in Python.pptxObject oriented Programming in Python.pptx
Object oriented Programming in Python.pptx
SHAIKIRFAN715544
 

Recently uploaded (20)

Introduction to AI agent development with MCP
Introduction to AI agent development with MCPIntroduction to AI agent development with MCP
Introduction to AI agent development with MCP
Dori Waldman
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
ijccmsjournal
 
Presentación Tomografía Axial Computarizada
Presentación Tomografía Axial ComputarizadaPresentación Tomografía Axial Computarizada
Presentación Tomografía Axial Computarizada
Juliana Ovalle Jiménez
 
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
BeHappy728244
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
SharinAbGhani1
 
IOt Based Research on Challenges and Future
IOt Based Research on Challenges and FutureIOt Based Research on Challenges and Future
IOt Based Research on Challenges and Future
SACHINSAHU821405
 
International Journal of Advance Robotics & Expert Systems (JARES)
International Journal of Advance Robotics & Expert Systems (JARES)International Journal of Advance Robotics & Expert Systems (JARES)
International Journal of Advance Robotics & Expert Systems (JARES)
jaresjournal868
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
MODULE 6 - 1 VAE - Variational Autoencoder
MODULE 6 - 1 VAE - Variational AutoencoderMODULE 6 - 1 VAE - Variational Autoencoder
MODULE 6 - 1 VAE - Variational Autoencoder
DivyaMeenaS
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbbTree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
Introduction to AI agent development with MCP
Introduction to AI agent development with MCPIntroduction to AI agent development with MCP
Introduction to AI agent development with MCP
Dori Waldman
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
ijccmsjournal
 
Presentación Tomografía Axial Computarizada
Presentación Tomografía Axial ComputarizadaPresentación Tomografía Axial Computarizada
Presentación Tomografía Axial Computarizada
Juliana Ovalle Jiménez
 
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
BeHappy728244
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
SharinAbGhani1
 
IOt Based Research on Challenges and Future
IOt Based Research on Challenges and FutureIOt Based Research on Challenges and Future
IOt Based Research on Challenges and Future
SACHINSAHU821405
 
International Journal of Advance Robotics & Expert Systems (JARES)
International Journal of Advance Robotics & Expert Systems (JARES)International Journal of Advance Robotics & Expert Systems (JARES)
International Journal of Advance Robotics & Expert Systems (JARES)
jaresjournal868
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
MODULE 6 - 1 VAE - Variational Autoencoder
MODULE 6 - 1 VAE - Variational AutoencoderMODULE 6 - 1 VAE - Variational Autoencoder
MODULE 6 - 1 VAE - Variational Autoencoder
DivyaMeenaS
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbbTree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
Ad

Problem solving with python programming OOP's Concept

  • 2. School of Computer Science & Artificial Intelligence Bura Vijay Kumar Assistant Professor, Email : [email protected] 2
  • 3. Course PROBLEM SOLVING USING PYTHON PROGRAMMING 3
  • 5. Overview Object-Oriented Programming: Introduction to Object Oriented Programming; Class Object Encapsulation; Inheritance; Polymorphism Abstraction
  • 6. Object Oriented Programming : ● Object Oriented Programming can be defined as a programming model which is based upon the concept of objects. ● Objects contain data in the form of attributes and code in the form of methods. In object oriented programming, computer programs are designed using the concept of objects that interact with real world. ● Languages used in Object Oriented Programming: Java, C++, C#, Python, PHP, JavaScript, Ruby, Perl, Objective-C, Dart, Swift, Scala.
  • 7. Advantages of Object Oriented Programming
  • 8. Object Oriented Programming Concepts ● Procedural Vs Object Oriented
  • 9. Object Oriented Programming : ● It supports All OOP's concepts ● In java everything is Object which has some data and behavior. ○ Object ○ Class ○ Abstraction ○ Encapsulation ○ Inheritance ○ Polymorphism
  • 10. Object Oriented Programming : Object: ● Object is an Real world Entity ● Instance of a class is called an Object. ● It has properties (attributes) ● Task performed (operations) Example: Human Attributes/Properties Tasks(Operations) Name walk() Color run() Height read() Etc.. Etc..
  • 11. Object Oriented Programming : Class: ● Class is a blue print that object follows ● A Class consist of ‘N’ Number of Object. ● Class is a collection of objects and there attributes, operations and there relationships Example: Student Variables/Properties Tasks(Operations) Name read() Roll No write() DoJ play() Etc.. Etc..
  • 12. Object Oriented Programming : Class: Example
  • 13. Abstraction ● Showing only essential parts, hiding the implementation details is called Abstraction. Example: Google play Store Android Applications .apk files .exe files
  • 14. Encapsulation ● Binding Variables and Methods under single Entity or ● Wrapping of data into Single Unit is called Encapsulation. Example:
  • 15. Inheritance ● Acquiring the properties of one class to another class is called Inheritance. Example: Types of Inheritance:  Single Inheritance  Multiple Inheritance  Multi-level Inheritance  Hierarchical Inheritance
  • 16. Polymorphism ● Performing same task in different ways is called Polymorphism. ● The ability of an object to take many forms. Example: Polymorphism can be achieved by ● Method Overloading – Compile Time ● Method Overriding – Run Time
  • 17. Python Classes and Objects Python Classes/Objects ● Python is an object oriented programming language. ● Almost everything in Python is an object, with its properties and methods. ● A Class is like an object constructor, or a "blueprint" for creating objects. Create a Class ● To create a class, use the keyword class: Example:
  • 18. Python Classes and Objects Python Classes/Objects Create Object ● Now we can use the class named MyClass to create objects: Example 1: ● Create an object named p1, and print the value of x: ● Example 2:
  • 21. Python Classes and Objects The __init__() Function ● Use the __init__() function to assign values to object properties, or other operations that are necessary to do when the object is being created. ● All classes have a function called __init__(), which is always executed when the class is being initiated. Example : Note: The __init__() function is called automatically every time the class is being used to create a new object.
  • 22. Python Classes and Objects Object Methods ● Objects can also contain methods. Methods in objects are functions that belong to the object. ● Let us create a method in the Person class: Example ● Insert a function that prints a greeting, and execute it on the p1 object:
  • 23. Python Classes and Objects The self Parameter ● The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class. ● It does not have to be named self , you can call it whatever you like, but it has to be the first parameter of any function in the class: Example: ● Use the words my_object and abc instead of self :
  • 24. Python Classes and Objects Modify Object Properties ● You can modify properties on objects like this: Example:
  • 25. Python Classes and Objects Delete Object Properties ● You can delete properties on objects by using the del keyword: Example: ● Delete the age property from the p1 object:
  • 26. Python Classes and Objects The pass Statement ● class definitions cannot be empty, but if you for some reason have a class definition with no content, put in the pass statement to avoid getting an error.
  • 27. Python Classes and Objects Python Inheritance ● Inheritance allows us to define a class that inherits all the methods and properties from another class. ● Parent class is the class being inherited from, also called base class. ● Child class is the class that inherits from another class, also called derived class.
  • 28. Python Inheritance In Single Inheritance one class extends another class (one class only).
  • 29. Python Inheritance ● In Multilevel Inheritance, one class can inherit from a derived class.
  • 30. Python Inheritance ● In Hierarchical Inheritance, one class is inherited by many sub classes.
  • 31. Python Inheritance ● In Multiple Inheritance, one class extending more than one class.
  • 32. Python Inheritance Create a Parent Class ● Any class can be a parent class, so the syntax is the same as creating any other class: Example ● Create a class named Person, with firstname and lastname properties, and a printname method:
  • 33. Python Inheritance Create a Child Class ● To create a class that inherits the functionality from another class, send the parent class as a parameter when creating the child class: Example ● Create a class named Student, which will inherit the properties and methods from the Person class: class Student(Person): pass Note: Use the pass keyword when you do not want to add any other properties or methods to the class. ● Now the Student class has the same properties and methods as the Person class.
  • 34. Python Inheritance Create a Child Class Example ● Use the Student class to create an object, and then execute the printname method:
  • 35. Python Inheritance Use the super() Function ● Python also has a super() function that will make the child class inherit all the methods and properties from its parent: class Student(Person): def __init__(self, fname, lname): super().__init__(fname, lname)
  • 39. What you learnt in this session Summary of the topic Specific topics: ● Sub topic 1 ● Sub topic 2
  • 40. If any questions Question 1 ● Option 1 ● Option 2 ● Option 3 ● Option 4 ● Option 1 ● Option 2 ● Option 3 ● Option 4 Question 2