Saturday, March 7, 2020

super in Inheritance in python


class a:
    def __init__(self,gene):
        print(gene,"this is initialisation")
        #print(d)
       
    def fn1(self):
        print("this is This is inside fn1")
        #print(d)


class b(a):
    def __init__(self,a):
        print("this is initialisation of b",a)
    def fn2(self,a):
        print(a,"this is This is inside fn2")
        super(). __init__('anil')
       
   
x=5     
buf=b(x)
buf.fn2(x)
print()
x='durgam'
buf=b(x)
buf.fn2(x)

output:
this is initialisation of b 5
5 this is This is inside fn2
anil this is initialisation

this is initialisation of b durgam
durgam this is This is inside fn2
anil this is initialisation

No comments:

Post a Comment

python class topic video