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)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay