DEV Community

Cristian Fernando
Cristian Fernando

Posted on

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

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more