Skip to content

Instantly share code, notes, and snippets.

@psicobyte
Created May 14, 2014 21:07
Show Gist options
  • Select an option

  • Save psicobyte/49cda1572b40bcfbefda to your computer and use it in GitHub Desktop.

Select an option

Save psicobyte/49cda1572b40bcfbefda to your computer and use it in GitHub Desktop.
Ejemplo elemental de herencia en Python
#!/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