super method in python explained with an example

Publicado el: 28 septiembre 2021
en el canal de: khalil alkebsi
171
14

The super method in python.
In this video, I am going to introduce the super method (also called super function) in python and how can you use it to organize your code and get rid of duplicate code lines when using classes in python. The super method allows subclasses (also called child classes) to access methods from superclasses ( also called parent classes). It is very easy to use and can save your time and simplify your code. Now, enjoy the video.

The code :

class student:
def __init__(self , name , id):
self.name = name
self.id =id

def basic_info(self):
print('name :' , self.name , '\t id : ' , self.id)

def print_id(self):
print('Id : ' , self.id)

class scholarship(student):
def __init__(self , name , id):
super().__init__(name , id)




class selfexpense(student):
def __init__(self, name, id , tuition , payment):
super().__init__(name , id)

self.tuition = tuition
self.payment = payment

Tom = scholarship(" Tom" , 209)
Tom.basic_info()
Ali = selfexpense("Ali" , 210 , 10000 , 2000)
Ali.basic_info()
Ali.print_id()


En esta página del sitio puede ver el video en línea super method in python explained with an example de Duración hora minuto segunda en buena calidad , que subió el usuario khalil alkebsi 28 septiembre 2021, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 171 veces y le gustó 14 a los espectadores. Disfruta viendo!