Advertisement
Sergio_Istea

recorrido lista while pop

May 4th, 2023
1,123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # Utilizando el método pop()
  4.  
  5. lista = [ "Nombre: Sergio", "Apellido: Pernas", "Edad: 41" ]
  6.  
  7.  
  8.  
  9.  
  10.  
  11. while len(lista) > 0:
  12.    
  13.     # en cada vuelta la lista pierde el indice 0
  14.     # y almacena su valor en la variable 'salida'
  15.     salida = lista.pop(0)
  16.  
  17.     print(salida)
  18.  
  19.  
  20. # ADVERTENCIA!!!!
  21. # al usar este método estamos vaciando la lista.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement