From 83416c491d68d0b037d37f20d55ca7d433f76abe Mon Sep 17 00:00:00 2001 From: cmoreno Date: Thu, 3 Sep 2026 18:10:07 -0300 Subject: [PATCH] name handling y Herencia --- clase_8/atributos.py | 24 ++++++++++++++++++++++++ clase_8/herencia.py | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 clase_8/atributos.py create mode 100644 clase_8/herencia.py diff --git a/clase_8/atributos.py b/clase_8/atributos.py new file mode 100644 index 0000000..8ab778b --- /dev/null +++ b/clase_8/atributos.py @@ -0,0 +1,24 @@ +class Persona: + + def __init__(self, nombre, edad): + self.nombre = nombre + self.__edad = edad #oculto el verdadero nombre del atributo + + def getEdad(self): + return self.__edad + + def setEdad(self, edad): + if edad > 0: + self.__edad = edad + else: + print("Edad incorrecta") + +persona1=Persona("Juan",30) +persona1.setEdad(10) +persona1.__edad=-500 #en realidad no estamos modificando el atributo original +persona1.__edad=-100 +print(persona1.getEdad()) +print(persona1.__edad) +print(persona1.__dict__) + + diff --git a/clase_8/herencia.py b/clase_8/herencia.py new file mode 100644 index 0000000..df48daf --- /dev/null +++ b/clase_8/herencia.py @@ -0,0 +1,17 @@ +class Persona: + + def __init__(self, nombre, edad): + self.nombre = nombre + self.edad= edad + + def saludar(self): + print(f"Hola, soy {self.nombre}") + +class Alumno(Persona): + + def estudiar(self): + print("Estoy estudiando") + +alumno1= Alumno("Juan", 17) +print(alumno1.nombre) +print(alumno1.edad) \ No newline at end of file