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
The technical storage or access that is used exclusively for statistical purposes. Free 2025 jamb questions and answers cbt answers jamb / jamb 2025 answers cbt answers jamb. Flutter is a versatile framework that is well suited for both app and web development.