next


Python Online Compiler

Local Global Varaible In Python
Encapsulation


x=12 #global Varaible
class Rain:
   
    def myfun(self):
        y=10  #local Variable
        print("Local Varialble of myfun ",y)
        print("Global Varialble of myfun ",x) 
    def mydisp(self):
        z=20; #local Variable
        print("Global Varialble of mydisp ",x)
       # print(y) Here y is local Varialbe of myfun
        print("Local Varialble of mydisp ",z)

r=Rain()
r.myfun()
r.mydisp()
OUTPUT: Local Varialble of myfun 10 Global Varialble of myfun 12 Global Varialble of mydisp 12 Local Varialble of mydisp 20

Python Program for Max Number using NoReturn type with NoParameters
methods

class Maxnum:
    def max(self):
        x=int(input("Enter x Value"))
        y=int(input("Enter y Value"))
        if(x>y):
            print("x is max")
        else:
            print("y is max")

m=Maxnum()
m.max()
OUTPUT: Enter x Value12 Enter y Value24 y is max

Python Program for Max Number using NoReturn type with Parameters

class Maxnum:
    def max(self,x,y):
        if(x>y):
            print("x is max")
        else:
            print("y is max")

m=Maxnum()
m.max(12,24)

OUTPUT: y is max

Python Program for Max Number using Return type with NoParameters

class Maxnum:
    def max(self):
        x=int(input("Enter x Value"))
        y=int(input("Enter y Value"))
        if(x>y):
            return "x is max"
        else:
            return "y is max"

m=Maxnum()
print(m.max())
OUTPUT: Enter x Value12 Enter y Value24 y is max

Python Program for Max Number using Return type with Parameters

class Maxnum:
    def max(self,x,y):
        
        if(x>y):
            return "x is max"
        else:
            return "y is max"

m=Maxnum()
print(m.max(12,24))
OUTPUT: y is max

Constructor Program In Python
Data abstruction


class Maxnum:
    def __init__(self):
        x=int(input("Enter x Value"))
        y=int(input("Enter y Value"))
        if(x>y):
            print("x is max")
        else:
            print("y is max")

m=Maxnum()
OUTPUT: Enter x Value12 Enter y Value24 y is max

Python Program for Max Number using NoReturn type with NoParameters With NoParameters Constructor
Constructor


class Maxnum:
    def __init__(self):
        self.x=int(input("Enter x Value"))
        self.y=int(input("Enter y Value"))
    def max(self):
        if(self.x>self.y):
            print("x is max")
        else:
            print("y is max")

m=Maxnum()
m.max()

OUTPUT: Enter x Value12 Enter y Value24 y is max

Python Program for Max Number using NoReturn type with Parameters With NoParametarized Constructor


class Maxnum:
    def __init__(self):
        self.x=int(input("Enter x Value"))
        self.y=int(input("Enter y Value"))
    def max(self,p,q):
        if(self.x>self.y):
            print("x is max")
        else:
            print("y is max")

m=Maxnum()
m.max(200,100)

OUTPUT: Enter x Value12 Enter y Value24 y is max

Python Program for Max Number using Return type with NoParameters With NoParametarized Constructor


class Maxnum:
    def __init__(self):
        self.x=int(input("Enter x Value"))
        self.y=int(input("Enter y Value"))
    def max(self):
        if(self.x>self.y):
            return "x is max"
        else:
            return "y is max"

m=Maxnum()
print(m.max())
OUTPUT: Enter x Value12 Enter y Value24 y is max

Python Program for Max Number using Return type with Parameters With NoParametarized Constructor


class Maxnum:
    def __init__(self):
        self.x=int(input("Enter x Value"))
        self.y=int(input("Enter y Value"))
    def max(self,p,q):
        if(self.x>self.y):
            return "x is max"
        else:
            return "y is max"

m=Maxnum()
print(m.max(200,100))

OUTPUT: Enter x Value12 Enter y Value24 y is max

Python Program for Max Number using NoReturn type with NoParameters With Parametarized Constructor


class Maxnum:
    def __init__(self,a,b):
        self.x=int(input("Enter x Value"))  # or  self.x=a
        self.y=int(input("Enter y Value"))  # or  self.y=y
    def max(self):
        if(self.x>self.y):
            print("x is max")
        else:
            print("y is max")

m=Maxnum(2000,1000)
m.max()

OUTPUT: Enter x Value12 Enter y Value24 y is max

Python Program for Max Number using NoReturn type with Parameters With Parametarized Constructor
                      

class Maxnum:
    def __init__(self,a,b):
        self.x=int(input("Enter x Value"))  # or  self.x=a
        self.y=int(input("Enter y Value"))  # or  self.y=b
    def max(self,p,q):
        if(self.x>self.y):
            print("x is max")
        else:
            print("y is max")

m=Maxnum(2000,1000)
m.max(200,100)

OUTPUT: Enter x Value12 Enter y Value24 y is max

Python Program for Max Number using Return type with NoParameters With Parametarized Constructor

class Maxnum:
    def __init__(self,a,b):
        self.x=int(input("Enter x Value"))  # or  self.x=a
        self.y=int(input("Enter y Value"))  # or  self.y=b
    def max(self):
        if(self.x>self.y):
            return "x is max"
        else:
            return "y is max"

m=Maxnum(2000,1000)
print(m.max())

OUTPUT: Enter x Value12 Enter y Value24 y is max

Python Program for Max Number using Return type with Parameters With Parametarized Constructor


class Maxnum:
    def __init__(self,a,b):
        self.x=int(input("Enter x Value"))  # or  self.x=a
        self.y=int(input("Enter y Value"))  # or  self.y=b
    def max(self,p,q):
        if(self.x>self.y):
            return "x is max"
        else:
            return "y is max"

m=Maxnum(2000,1000)
print(m.max(200,100))
OUTPUT: Enter x Value12 Enter y Value24 y is max

Single Inheritance In Python
Inheritance

class Parent:
    def  __init__(self):
        self.name=input("Enter  Name")
        self.location=input("Enter Location")
        self.gender=input("Enter Gender")
class Child(Parent):
    def __init__(self):
        Parent.__init__(self)
        self.marks=int(input("Enter Marks"))
    def display_Details(self):
        print("Your Name is",self.name)
        print("Your Location is",self.location)
        print("Your Gender is",self.gender)
        print("Your Marks is",self.marks)

#Create Object For Child Class
c=Child()
c.display_Details()
        
        

OUTPUT: Enter Namesateesh Enter Locationchennai Enter Gendermale Enter Marks24 Your Name is sateesh Your Location is chennai Your Gender is male Your Marks is 24

MultiLevel Inheritance In Python

class Parent:
    def  __init__(self):
        self.name=input("Enter  Name")
        self.location=input("Enter Location")
        self.gender=input("Enter Gender")
class Child(Parent):
    def  __init__(self):
        Parent.__init__(self)
        self.Address=input("Enter  Address")
    
class Child1(Child):
    def __init__(self):
        Child.__init__(self)
        self.marks=int(input("Enter Marks"))
    def display_Details(self):
        print("Your Name is",self.name)
        print("Your Location is",self.location)
        print("Your Gender is",self.gender)
        print("Your Marks is",self.marks)

#Create Object For Child Class
c=Child1()
c.display_Details()
        
        

OUTPUT: Enter NameSateesh Enter LocationChennai Enter GenderMale Enter AddressChennai Enter Marks24 Your Name is Sateesh Your Location is Chennai Your Gender is Male Your Marks is 24

Hierarchical inheritance In Python


class Parent:
    def  __init__(self):
        self.name=input("Enter  Name")
        self.location=input("Enter Location")
        self.gender=input("Enter Gender")
        self.Address=input("Enter  Address")
           
class Student(Parent):
    def __init__(self):
        Parent.__init__(self)
        self.marks=int(input("Enter Marks"))
    def display_Details(self):
        print("Strudent Details Are ......................")
        print("Your Name is",self.name)
        print("Your Location is",self.location)
        print("Your Gender is",self.gender)
        print("Your Marks is",self.marks)
        print(" ")
class Faculty(Parent):
    def __init__(self):
        Parent.__init__(self)
        self.salary=int(input("Enter Salary"))
    def display_Details(self):
        print("Faculty Details Are ......................")
        print("Your Name is",self.name)
        print("Your Location is",self.location)
        print("Your Gender is",self.gender)
        print("Your Salary is",self.salary)
        print(" ")

class Principal(Parent):
    def __init__(self):
        Parent.__init__(self)
        self.salary=int(input("Enter Salary"))
    def display_Details(self):
        print("Principal Details Are ......................")
        print("Your Name is",self.name)
        print("Your Location is",self.location)
        print("Your Gender is",self.gender)
        print("Your Salary is",self.salary)
        print(" ")


#Create Objects For Child Classes
s=Student()
s.display_Details()
f=Faculty()
f.display_Details()
p=Principal()
p.display_Details()
        
        

OUTPUT: Enter NameSateesh Enter LocationChennai Enter GenderMale Enter AddressChennai Enter Marks24 Strudent Details Are ...................... Your Name is Sateesh Your Location is Chennai Your Gender is Male Your Marks is 24 Enter NameVarshini Enter LocationChennai Enter GenderFemale Enter AddressChennai Enter Salary24000 Faculty Details Are ...................... Your Name is Varshini Your Location is Chennai Your Gender is Female Your Salary is 24000 Enter NamePriya Enter LocationCHennai Enter GenderFemale Enter AddressChennai Enter Salary240000 Principal Details Are ...................... Your Name is Priya Your Location is Chennai Your Gender is Female Your Salary is 240000

Multiple Inheritance In Python

class Parent1:
    def  __init__(self):
        self.name=input("Enter  Name")
        self.location=input("Enter Location")
        self.gender=input("Enter Gender")
        
           
class Parent2:
    def __init__(self):
        self.Address=input("Enter  Address")
   
class Child(Parent1,Parent2):
    def __init__(self):
        Parent1.__init__(self)
        Parent2.__init__(self)
        self.salary=int(input("Enter Salary"))
    def display_Details(self):
       
        print("Your Name is",self.name)
        print("Your Location is",self.location)
        print("Your Gender is",self.gender)
        print("Your Salary is",self.salary)
        print(" ")


#Create Object For Child Class
p=Child()
p.display_Details()
        
OUTPUT: Enter NameVarshini Enter LocationChennai Enter GenderFemale Enter AddressChennai Enter Salary24000 Your Name is Varshini Your Location is Chennai Your Gender is Female Your Salary is 24000

Hybrid Inheritance In Python

class Parent1:
    def  __init__(self):
        self.name=input("Enter  Name")
        self.location=input("Enter Location")
        self.gender=input("Enter Gender")
        
           
class Parent2:
    def __init__(self):
        self.address=input("Enter  Address")
   
class Child(Parent1,Parent2):
    def __init__(self):
        Parent1.__init__(self)
        Parent2.__init__(self)
        self.salary=int(input("Enter Salary"))
    def display_Details(self):
        print("Child 1 Details")
        print("Your Name is",self.name)
        print("Your Location is",self.location)
        print("Your Gender is",self.gender)
        print("Your Salary is",self.salary)
        print("Your Address is",self.address)
        print(" ")
class Child1(Parent2):
    def __init__(self):
        self.name=input("Enter name")
        Parent2.__init__(self)
    def  display_Details(self):
         print("Child 2 Details")
         print("Your Name is",self.name)
         print("Your Address is",self.address)
        

#Create Object For Child Class
p=Child()
p.display_Details()
c=Child1()
c.display_Details()
OUTPUT: Enter Name Sateesh Enter Location Chennai Enter Gender Male Enter Address Chennai Enter Salary 24000 Child 1 Details Your Name is Sateesh Your Location is Chennai Your Gender is Male Your Salary is 24000 Your Address is Chennai Enter name Varshini Enter Address Chennai Child 2 Details Your Name is Varshini Your Address is Chennai

>>>>