teslariu

str como coleccion

Jun 24th, 2023
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. !/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Tipo especial (yo lo llamo así): str
  6.  
  7. EL TIPO STR ES UN TIPO DE DATO BASICO PERO TAMBIEN ES UNA COLECCION
  8.  
  9. str es una coleccion ORDENADA e INMUTABLE
  10.  
  11. frase= "Las mariposas son bellas"
  12.  
  13. print(f"Cantidad de caracteres de la frase '{frase}': {len(frase)}")
  14. print(f"Inicial: {frase[0]}")
  15. # frase[0] = "l" # da error, es INMUTABLE
  16. """
  17.  
  18. # Script que imprime una lista en forma vertical
  19. lista = ["Juan", "Pepe", "Ana", "Sofia"]
  20.  
  21. i = 0
  22. while i < len(lista):
  23.     print(lista[i])
  24.     i = i +1  
  25.  
  26. # Spoiler del for    
  27. for nombre in lista:
  28.     print(nombre)    
  29.    
Advertisement
Add Comment
Please, Sign In to add comment