Basic oops Concept in python

 Basic oops Concept in python



  1. Class
  2. Object
  3. polymorphism
  4. Inheritance
  5. Abstraction
  6. Encapsulation

Class A Class is a specification or blue print or template of an object
Object Object is instance of class. it is dynamic memory allocation of class.
Inheritance It is used to achieve concept of re-usability. inshort, inheritance means to take something that already made.
Polimorphism It is process to represent any things in multiple forms
Abstraction Abstraction is a process to show only useful data and remaining hide from user.
Encapsulation Encapsulation is like enclosing in a capsule. like your bag in which you can keep your pen, books, etc

1. Class and Object

Attributes - Variable

Behavior - Methods(Function)

class Student:
def stud(self):
print("shreyash, shubham, pratik, carry")

st= Student()
Student.stud(st)

Output

shreyash, shubham, pratik, carry
1.__init__
class Student:
#__init__ to initialise the variable
def __init__(self, id,name):
self.id = id
self.name = name

def stud(self):
print(f"Student_info : id : {self.id} name : {self.name}") #using f-string

#objects
st1= Student(1, 'shreyash')
st2= Student(2, 'pratik')
st3= Student(3, 'shubham')

st1.stud()
st2.stud()
st3.stud()

Output

Student_info : id : 1 name : shreyash
Student_info : id : 2 name : pratik
Student_info : id : 3 name : shubham