Advertisement
jsbsan

crear clase y herencia en python

Jun 10th, 2013
1,565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. class cosa():
  2.     nombre=""
  3.     apellidos=""
  4.     def nombre(self,n,a):
  5.         self.nombre=n
  6.         self.apellidos=a
  7.     def ver(self):
  8.         print self.nombre , self.apellidos
  9.  
  10. class robot(cosa):
  11.     def calculista(self):
  12.         print "se calcular muy rapido"
  13.     def ver(self):
  14.         print "Soy un robotito...",self.nombre , self.apellidos
  15.  
  16.  
  17. class humano(cosa):
  18.     def calculista(self):
  19.         print "calculo a mano"
  20.  
  21. def main():
  22.     lista = []
  23.     r1=robot()
  24.  
  25.     r1.nombre("R2","D2")
  26.     r2=humano()
  27.     r2.nombre("Julio","anchez")
  28.  
  29.     r2.ver()
  30.     r2.calculista()
  31.  
  32.     r1.ver()
  33.     r1.calculista()
  34.  
  35.     lista.append(r1)
  36.     lista.append(r2)
  37.  
  38.     print "Listado...."
  39.     lista[0].ver()
  40.     lista[0].calculista()
  41.  
  42.     lista[1].ver()
  43.     lista[1].calculista()
  44.     pass
  45.  
  46. if __name__ == '__main__':
  47.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement