DEV Community

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

Posted on

1

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

Explica este código Python

Dificultad: Intermedio

def f():
    return (1,2)
    pass

a, b = f()
print(b)
Enter fullscreen mode Exit fullscreen mode
  • A. 1
  • B. 2
  • C. pass
  • D. SyntaxError

Respuesta:

👉 B. 2

Las funciones en Python pueden regresar cualquier tipo de dato o estructura de dato, en este caso regresamos una tupla.

Como el valor de retorno es una tupla entonces podemos usar el desempaquetado de tuplas usando las variables a y b para ello.

Finalmente imprimimos el segundo valor de la tupla que es 2.

Todo código que vaya luego del return nunca se ejecuta, por ello pass no tiene sentido en este ejemplo y solo se lo uso para distraer.

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay