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

Cristian Fernando - Jul 12 - - Dev Community

Explica este código Python

Dificultad: Intermedio

def f(x, y, z):
    return x * y * z

print(f(4, z=2, y=2))
Enter fullscreen mode Exit fullscreen mode
  • A. 8
  • B. 16
  • C. 2
  • D. SyntaxError

Respuesta:

👉 B. 16

Es posible mezclar tanto argumentos posicionales como argumentos nombrados en una función.

La única condición es que los argumentos posicionales deben ir siempre antes que los argumentos nombrados, solo así no se producirá un error.

Por ejemplo, el siguiente código sería incorrecto:

def f(x, y, z):
    return x * y * z

print(f(z=2, 4, y=2)) # SyntaxError: positional argument follows keyword argument
Enter fullscreen mode Exit fullscreen mode

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player