DEV Community

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

Posted on

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

Explica este código Python

Dificultad: Fácil

def f(a, b , *, c):
    return {
        a:a,
        b:b,
        c:c
    }

print(f(1,2,3))
Enter fullscreen mode Exit fullscreen mode
  • A. {1:1, 2:2, c:"*"}
  • B. {a:1, b:2, c:3}
  • C. {1:1, 2:2, 3:3}
  • D. Error

Respuesta:

👉 D. Error

En python podemos establecer una sintaxis especial para administrar los parámetros de nuestras funciones.

Cuando veas un * en los parámetros de una función significa que todos los parámetros escritos a la derecha de dicho * obligatoriamente deben ser parámetros nombrados.

Entonces al llamar a la función f(1,2,3) estamos cometiendo un error puesto que en esta llamada todos los argumentos son posicionales.

La manera correcta de llamarlo sería: f(1,2,c=3) donde c es un argumento nombrado obligatorio.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

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

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay