herencia python 1

herencia python

class Persona:
    def __init(self, nombre):
        self.nombre = nombre

class Estudiante(Persona):
    def __init(self, nombre, curso):
        super().__init__(nombre)
        self.curso = curso 

Here is what the above code is Doing:
1. We create a class called Persona.
2. We create a class called Estudiante that inherits from Persona.
3. We create a method called __init__ in the Estudiante class.
4. We call the __init__ method of the Persona class using super().
5. We pass the nombre argument to the __init__ method of the Persona class.
6. We create an attribute called curso in the Estudiante class.

Similar Posts