56 - Intro to oops

🧢 Tags:: #Python_Basics
Up:: 57 - Classes and Objects
Down:: 55 - Exercise 5
πŸ—ƒ Resources:: Playlist
2024-02-04 - 22:02

Introduction to Object-Oriented Programming in Python: In programming languages, mainly there are two approaches that are used to write program or code.

The procedure we are following till now is the β€œProcedural Programming” approach. So, in this session, we will learn about Object Oriented Programming (OOP). The basic idea of object-oriented programming (OOP) in Python is to use classes and objects to represent real-world concepts and entities.

A class is a blueprint or template for creating objects. It defines the properties and methods that an object of that class will have. Properties are the data or state of an object, and methods are the actions or behaviors that an object can perform.

An object is an instance of a class, and it contains its own data and methods. For example, you could create a class called "Person" that has properties such as name and age, and methods such as speak() and walk(). Each instance of the Person class would be a unique object with its own name and age, but they would all have the same methods to speak and walk.

One of the key features of OOP in Python is encapsulation, which means that the internal state of an object is hidden and can only be accessed or modified through the object's methods. This helps to protect the object's data and prevent it from being modified in unexpected ways.

Another key feature of OOP in Python is inheritance, which allows new classes to be created that inherit the properties and methods of an existing class. This allows for code reuse and makes it easy to create new classes that have similar functionality to existing classes.

Polymorphism is also supported in Python, which means that objects of different classes can be treated as if they were objects of a common class. This allows for greater flexibility in code and makes it easier to write code that can work with multiple types of objects.

In summary, OOP in Python allows developers to model real-world concepts and entities using classes and objects, encapsulate data, reuse code through inheritance, and write more flexible code through polymorphism.

Main Example

def hello():

sales1 = 6000
profit1 = 2000
ad1 = 1000
# rajeev.sales

sales2 = 6000
profit2 = 2000
ad2 = 1000 
# vikrant.sales

sales3 = 6000
profit3 = 2000
ad3 = 1000
RailwayForm   ---> Class [blueprint]
harry --> harry ki info wala form --> Object [entity]
tom --> tom ki info wala form --> Object [entity]
shubham --> shubham ki info wala form --> Object [entity]
# shubham.changeName("Shubhi")