Ibuprofeno.py💊| #151: Explica este código Python

Explica este código Python

Dificultad: Fácil

my_tuple = (1,2,3)
my_tuple[0] = 4
print(my_tuple)
Enter fullscreen mode Exit fullscreen mode
  • A. TypeError
  • B. (1,2,3)
  • C. (4,2,3)
  • D. (4,1,2,3)

Respuesta:

👉 A. TypeError

Por definición recordemos que una tupla es una estructura de datos inmutable, por tanto no es posible hacer asignaciones nuevas sobre elementos ya existentes. Esto producirá un error.

Si la tupla fuera una lista no habría ningún problema:

my_list= [1,2,3]
my_list[0] = 4
print(my_list) # [4,2,3]
Enter fullscreen mode Exit fullscreen mode


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Another standout feature of cloudystorage is its commitment to delivering best value cloud storage provider services. Copyright © 2024 solid future. Cart urban safari pet.