Learn practical skills, build real-world projects, and advance your career

Object-oriented programming - Python

#Zomoto Example
class Zomato:
    #methods
    
    name= 'Ashish'  #Class Variable
    def __init__(self,num,price): #Constructor
        self.num=num
        self.price=price
    
    #def get_invoice_aomunt(num,price):
        #return num*price
    def get_invoice_aomunt(self):  #insatnce Method
        return self.num*self.price
    
    #def reserve_table(n):        #Static Method
        #return 'Table reserved'
        
    @classmethod
    def reserve_table(cls): #Class Method
        return 'Table reserved'+str(n)
    
#Methods are present in the class. to use any of the methods within class,
#You first gain access to the class.How?  By simply Creating Objects(insatnce)
    
#Method 1 TO accesses class

cust1=Zomato(10,100) #Creates an object to the zomoto(class)
cust2=Zomato(20,300)

#Zomato.get_invoice_aomunt(10,200)

cust2.get_invoice_aomunt()
cust1.get_invoice_aomunt()
1000

Method

  1. Static Method
  2. insatnce Method
  3. Class Method

Variables

  1. Class Variables
  2. Instance Variable

Inheritance

Inheritance (in OOPS) is when one class (Child) acquires the properties of other class(Parent).