Object oriented Programming in Python
What is Object Oriented Programming in Python  Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects". The object contains both data and code: Data in the form of properties (often known as attributes), and code, in the form of methods (actions object can perform).
 An object-oriented paradigm is to design the program using classes and objects. Python programming language supports different programming approaches like functional programming, modular programming. One of the popular approaches is object- oriented programming (OOP) to solve a programming problem is by creating objects
Oops Concepts
What is a Class and Objects in Python? • Class: The class is a user-defined data structure that binds the data members and methods into a single unit. Class is a blueprint or code template for object creation. Using a class, you can create as many objects as you want. • Object: An object is an instance of a class. It is a collection of attributes (variables) and methods. We use the object of a class to perform actions.
 Objects have two characteristics: They have states and behaviors (object has attributes and methods attached to it) Attributes represent its state, and methods represent its behavior. Using its methods, we can modify its state.  In short, Every object has the following property. • Identity: Every object must be uniquely identified. • State: An object has an attribute that represents a state of an object, and it also reflects the property of an object. • Behavior: An object has methods that represent its behavior. Objects
class and objects in Python Example:
A real-life example of class and objects. Object 1: Jessa • State: • Name: Jessa • Sex: Female • Profession: Software Engineer • Behavior: • Working: She is working as a software developer at ABC Company • Study: She studies 2 hours a day Object 2: Jon • State: • Name: Jon • Sex: Male • Profession: Doctor • Behavior: • Working: He is working as a doctor • Study: He studies 5 hours a day Class: Person •State: Name, Sex, Profession •Behavior: Working, Study Using the above class, we can create multiple objects that depict different states and behavior.
 As you can see in previous example, Jessa is female, and she works as a Software engineer. On the other hand, Jon is a male, and he is a lawyer. Here, both objects are created from the same class, but they have different states and behaviors.
Create a Class in Python  In this example, we are creating a Person Class with name, sex, and profession instance variables. Example: Define a class in Python
Create Object of a Class  An object is essential to work with the class attributes. The object is created using the class name. When we create an object of the class, it is called instantiation. The object is also called the instance of a class. Below is the code to create the object of a Person class In Python, Object creation is divided into two parts in Object Creation and Object initialization using the __init__() method we can implement constructor to initialize the object.
How Does the init Method Work? The init method in python is a special method used in the process of initializing an object. When you create a new instance of a class, the init method is automatically called. It simply initialize the class object. The method __init__ can is being used to implement inheritance in Python, which is a way of creating classes that inherit behaviors and attributes from other classes. This is done by creating a new class that inherits from an existing class by using the keyword class followed by the name of the new class and the name of the base class in quotes.
 Complete Example
Read the following articles  https://realpython.com/python3-object-oriented-programming/  https://www.datamentor.io/python/classes-object  https://www.learnpython.org/en/Classes_and_Objects

Object oriented Programming in Python.pptx

  • 1.
  • 2.
    What is ObjectOriented Programming in Python  Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects". The object contains both data and code: Data in the form of properties (often known as attributes), and code, in the form of methods (actions object can perform).
  • 3.
     An object-orientedparadigm is to design the program using classes and objects. Python programming language supports different programming approaches like functional programming, modular programming. One of the popular approaches is object- oriented programming (OOP) to solve a programming problem is by creating objects
  • 4.
  • 5.
    What is aClass and Objects in Python? • Class: The class is a user-defined data structure that binds the data members and methods into a single unit. Class is a blueprint or code template for object creation. Using a class, you can create as many objects as you want. • Object: An object is an instance of a class. It is a collection of attributes (variables) and methods. We use the object of a class to perform actions.
  • 6.
     Objects havetwo characteristics: They have states and behaviors (object has attributes and methods attached to it) Attributes represent its state, and methods represent its behavior. Using its methods, we can modify its state.  In short, Every object has the following property. • Identity: Every object must be uniquely identified. • State: An object has an attribute that represents a state of an object, and it also reflects the property of an object. • Behavior: An object has methods that represent its behavior. Objects
  • 7.
    class and objectsin Python Example:
  • 8.
    A real-life exampleof class and objects. Object 1: Jessa • State: • Name: Jessa • Sex: Female • Profession: Software Engineer • Behavior: • Working: She is working as a software developer at ABC Company • Study: She studies 2 hours a day Object 2: Jon • State: • Name: Jon • Sex: Male • Profession: Doctor • Behavior: • Working: He is working as a doctor • Study: He studies 5 hours a day Class: Person •State: Name, Sex, Profession •Behavior: Working, Study Using the above class, we can create multiple objects that depict different states and behavior.
  • 9.
     As youcan see in previous example, Jessa is female, and she works as a Software engineer. On the other hand, Jon is a male, and he is a lawyer. Here, both objects are created from the same class, but they have different states and behaviors.
  • 10.
    Create a Classin Python  In this example, we are creating a Person Class with name, sex, and profession instance variables. Example: Define a class in Python
  • 11.
    Create Object ofa Class  An object is essential to work with the class attributes. The object is created using the class name. When we create an object of the class, it is called instantiation. The object is also called the instance of a class. Below is the code to create the object of a Person class In Python, Object creation is divided into two parts in Object Creation and Object initialization using the __init__() method we can implement constructor to initialize the object.
  • 12.
    How Does theinit Method Work? The init method in python is a special method used in the process of initializing an object. When you create a new instance of a class, the init method is automatically called. It simply initialize the class object. The method __init__ can is being used to implement inheritance in Python, which is a way of creating classes that inherit behaviors and attributes from other classes. This is done by creating a new class that inherits from an existing class by using the keyword class followed by the name of the new class and the name of the base class in quotes.
  • 13.
  • 14.
    Read the followingarticles  https://realpython.com/python3-object-oriented-programming/  https://www.datamentor.io/python/classes-object  https://www.learnpython.org/en/Classes_and_Objects