teslariu

for

Feb 4th, 2022
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # ejemplo de imprimir una lista verticalmente con while y for
  5. # no es recomendado, la listas tienen tamaƱo definido, --> usar for
  6.  
  7. # TODA COLECCION ES ITERABLE
  8.  
  9. # for <variable iteradora>  in <iterable>:
  10.  
  11.  
  12. lista = ["Juan", "Ana", "Josefa", "Tito"] # len(lista) --> 4
  13.  
  14. indice = 0
  15.  
  16. while indice < len(lista):
  17.     print(lista[indice])
  18.     indice = indice + 1
  19.  
  20.    
  21. for nombre in lista:
  22.     print(nombre)
  23.    
  24. for letra in "murcielago":
  25.     print(letra)
  26.    
Advertisement
Add Comment
Please, Sign In to add comment