DEV Community

Cover image for Ibuprofeno.py💊| #186: Explica este código Python
Cristian Fernando
Cristian Fernando

Posted on

1

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

Explica este código Python

Dificultad: Fácil

cl = ('a',)
print(cl)
Enter fullscreen mode Exit fullscreen mode
  • A. a
  • B. ('a',)
  • C. ('a')
  • D. 'a'

Respuesta:

👉 B. ('a',)

Las tuplas en Python se crean usando la sintaxis de parentesis, pero es super importante que si queremos crear un tupla de un solo elemento pongamos una coma, esto se hace para que python no confunda la tupla con una cadena de texto.

Si tuviéramos:

cl = ('a') # sin la coma al final, esto es una cadena para python
Enter fullscreen mode Exit fullscreen mode

Esto es una peculiaridad de python que he visto en muchos portales y es una buena pregunta trampa para saber que tanto del leguaje sabe un programador.


Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

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