Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. class prueba:
  4.     def __init__(self):
  5.         self.lista = []
  6.  
  7.     def anadir(self, v):
  8.         self.lista.append(v)
  9.    
  10.     def anadir_varios(self, v):
  11.         for a in v:
  12.             prueba.anadir(self, a)
  13.  
  14.  
  15. class prueba2(prueba):
  16.     def __init__(self):
  17.         super().__init__()
  18.         self.contador = 0
  19.  
  20.     def anadir(self, v):
  21.         super().anadir(v)
  22.         self.contador += 1
  23.  
  24.     def anadir_varios(self, v):
  25.         super().anadir_varios(v)
  26.         self.contador += len(v)
  27.  
  28.  
  29. p = prueba2()
  30. p.anadir_varios([1, 2, 3])
  31. print("Cantidad: {:}".format(p.contador))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement