Created
May 14, 2014 21:07
-
-
Save psicobyte/49cda1572b40bcfbefda to your computer and use it in GitHub Desktop.
Ejemplo elemental de herencia en Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| #coding: utf-8 | |
| # Ejemplo de herencia. | |
| class Mamifero(): | |
| def __init__(self): | |
| descrpcion= "Los mamíferos son interesantes" | |
| def tiene_pelo(self): | |
| return "si" | |
| # Al poner Mamifero en el paréntesis, le decimos que herede de esa calse | |
| class Gato(Mamifero): | |
| def __init__(self): | |
| descrpcion= "Los gatos molan" | |
| def maulla(self): | |
| return "si" | |
| # Mascota es una instancia de la clase Gato | |
| Mascota = Gato() | |
| # Estamos llamando a un método que, en realidad, pertenece a la clase mamífero | |
| print Mascota.tiene_pelo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment