Python super() Function

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

Program 1

#Super method in python
# class A:
#     def __init__(self):
#         print("A")

# class B(A):
#     def __init__(self):
#         super().__init__()
#         print("B")

# class C(B):
#     def __init__(self):
#         super().__init__()
#         print("C")


# A1=A()
# print("-------------")
# B1=B()        
# print("-------------")
# C1=C()

#Multiple Inheritance

# class A(object):
#     def __init__(self):
#         super().__init__()
#         print("A")

# class B(object):
#     def __init__(self):
#         super().__init__()
#         print("B")

# class C(B,A):
#     def __init__(self):
#         super().__init__()
#         print("C")
# #Calling (Main)        

# C1=C()

# class Student:
#     def __init__(self,rno,name,email):
#         self.rno=rno
#         self.name=name
#         self.email=email

# class Result(Student):
#     def __init__(self,rno,name,email,hindi,maths,comp,eng):
#          super().__init__(rno,name,email)
#          self.hindi=hindi
#          self.maths=maths
#          self.comp=comp
#          self.eng=eng
#     def display(self):
#         print(self.rno)
#         print(self.name)
#         print(self.email)
#         print(self.hindi)
#         print(self.maths)
#         print(self.comp)
#         print(self.eng)

        
# #Calling 
# rn=int(input("Enter Roll No"))
# nm=input("Enter Name")
# em=input("Enter Email Id")
# h=int(input("Enter Hindi Marks"))
# m=int(input("Enter Maths Marks"))
# c=int(input("Enter Computer Marks "))
# e=int(input("Enter English Marks "))

# R=Result(rn,nm,em,h,m,c,e)
# R.display()


class First:
    def addition(self,a,b):
        return(a+b)
    
class Second(First):
    def addition(self,a,b,c,d):
        print(super().addition(a,b))
        return(a+b+c+d)

S=Second()
print(S.addition(50,20,60,70))

 

Your opinion matters
Please write your valuable feedback about DataFlair on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *