Python Object Oriented Programming Ms Smriti Sharma
OOP Object-oriented programming (OOP) involves programming using objects. An object represents an entity in the real-world that can be distinctly identified. An object consists of identity, state, and behavior. โ€ข Identity: It gives a unique name to an object. โ€ข State: It reflects the properties of an object. โ€ข Behavior: It reflects the response of an object with other objects.
Characteristics of OOPs โ€ข OOPs uses a bottom-up approach. โ€ข The program is divided into objects. โ€ข OOPs uses access modifiers. โ€ข OOPs is more secure than procedural languages. โ€ข Objects can move freely within member functions.
Classes Class is a template/blue-print for real-world entities Properties Behavior โ€ข Color โ€ข Cost โ€ข Battery Life โ€ข Make Calls โ€ข Watch Videos โ€ข Play Games
Class in Python Class is a user-defined data-type Mobile int float bool str
Attributes and Methods color cost Play Game Make Call Attributes Methods Methods are functions defined inside a class. They are invoked by objects to perform actions on other objects. Attributes are defined within a class and outside any method. Attributes define the characteristics of any object.
Objects Objects are specific instances of a class Apple Samsung Motorola
Objects in Python Apple Samsung Motorola a = 10 b = 20 c = 30 Specific instances of Mobile data type Specific instances of integer data type
Creating the first Class Creating the โ€˜Phoneโ€™ class Instantiating the โ€˜p1โ€™ object Invoking methods through object
Adding parameters to the class Setting and Returning the attribute values
Creating a class with Constructor init method acts as the constructor __init__ is a method that is automatically called when memory is allocated to a new object. For invoking in build parameter with object , self is used .
Instantiating Object Instantiating the โ€˜e1โ€™ object Invoking the โ€˜employee_detailsโ€™ method
Inheritance in Python With inheritance one class can derive the properties of another class Man inheriting features from his father
Inheritance Example Creating the base class Instantiating the object for base class
Inheritance Example Creating the child class Instantiating the object for child class Invoking the child class method
Over-riding init method Over-riding init method Invoking show_details() method from parent class Invoking show_car_details() method from child class
Types of Inheritance Single Inheritance Multiple Inheritance Multi-level Inheritance Hybrid Inheritance
Multiple Inheritance Child Parent 1 Parent 2 In multiple inheritance, the child inherits from more than 1 parent class
Multiple Inheritance in Python Parent Class One Parent Class Two Child Class
Multiple Inheritance in Python Instantiating object of child class Invoking methods
Multi-Level Inheritance Parent In multi-level Inheritance, we have Parent, child, grand-child relationship Child Grand-Child
Multi-Level Inheritance in Python Parent Class Child Class Grand-Child Class
Multi-Level Inheritance in Python Instantiating object of GrandChild class Invoking class methods
Definitions : Abstraction is the property by virtue of which only the essential details are displayed to the user. Encapsulation is a process of binding data members and member functions into a single unit. Encapsulation hides the state of a structured data object inside a class, preventing unauthorized access to an unauthorized person. Polymorphism is a Greek word that means many shaped. Polymorphism is the ability of a message to be displayed in more than one form.

OOP concepts -in-Python programming language

  • 1.
    Python Object OrientedProgramming Ms Smriti Sharma
  • 2.
    OOP Object-oriented programming (OOP)involves programming using objects. An object represents an entity in the real-world that can be distinctly identified. An object consists of identity, state, and behavior. โ€ข Identity: It gives a unique name to an object. โ€ข State: It reflects the properties of an object. โ€ข Behavior: It reflects the response of an object with other objects.
  • 3.
    Characteristics of OOPs โ€ขOOPs uses a bottom-up approach. โ€ข The program is divided into objects. โ€ข OOPs uses access modifiers. โ€ข OOPs is more secure than procedural languages. โ€ข Objects can move freely within member functions.
  • 4.
    Classes Class is atemplate/blue-print for real-world entities Properties Behavior โ€ข Color โ€ข Cost โ€ข Battery Life โ€ข Make Calls โ€ข Watch Videos โ€ข Play Games
  • 5.
    Class in Python Classis a user-defined data-type Mobile int float bool str
  • 6.
    Attributes and Methods color cost PlayGame Make Call Attributes Methods Methods are functions defined inside a class. They are invoked by objects to perform actions on other objects. Attributes are defined within a class and outside any method. Attributes define the characteristics of any object.
  • 7.
    Objects Objects are specificinstances of a class Apple Samsung Motorola
  • 8.
    Objects in Python AppleSamsung Motorola a = 10 b = 20 c = 30 Specific instances of Mobile data type Specific instances of integer data type
  • 9.
    Creating the firstClass Creating the โ€˜Phoneโ€™ class Instantiating the โ€˜p1โ€™ object Invoking methods through object
  • 10.
    Adding parameters tothe class Setting and Returning the attribute values
  • 11.
    Creating a classwith Constructor init method acts as the constructor __init__ is a method that is automatically called when memory is allocated to a new object. For invoking in build parameter with object , self is used .
  • 12.
    Instantiating Object Instantiating theโ€˜e1โ€™ object Invoking the โ€˜employee_detailsโ€™ method
  • 13.
    Inheritance in Python Withinheritance one class can derive the properties of another class Man inheriting features from his father
  • 14.
    Inheritance Example Creating thebase class Instantiating the object for base class
  • 15.
    Inheritance Example Creating thechild class Instantiating the object for child class Invoking the child class method
  • 16.
    Over-riding init method Over-ridinginit method Invoking show_details() method from parent class Invoking show_car_details() method from child class
  • 17.
    Types of Inheritance SingleInheritance Multiple Inheritance Multi-level Inheritance Hybrid Inheritance
  • 18.
    Multiple Inheritance Child Parent 1Parent 2 In multiple inheritance, the child inherits from more than 1 parent class
  • 19.
    Multiple Inheritance inPython Parent Class One Parent Class Two Child Class
  • 20.
    Multiple Inheritance inPython Instantiating object of child class Invoking methods
  • 21.
    Multi-Level Inheritance Parent In multi-levelInheritance, we have Parent, child, grand-child relationship Child Grand-Child
  • 22.
    Multi-Level Inheritance inPython Parent Class Child Class Grand-Child Class
  • 23.
    Multi-Level Inheritance inPython Instantiating object of GrandChild class Invoking class methods
  • 24.
    Definitions : Abstraction isthe property by virtue of which only the essential details are displayed to the user. Encapsulation is a process of binding data members and member functions into a single unit. Encapsulation hides the state of a structured data object inside a class, preventing unauthorized access to an unauthorized person. Polymorphism is a Greek word that means many shaped. Polymorphism is the ability of a message to be displayed in more than one form.