DEV Community

Cristian Fernando
Cristian Fernando

Posted on

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

Explica este código Python

Dificultad: Intermedio

from functools import reduce

res_reduce = reduce(lambda x,y : x+y, range(0,5))
print(res_reduce)
Enter fullscreen mode Exit fullscreen mode
  • A. 11
  • B. 9
  • C. 10
  • D. 8

Respuesta:

👉 C. 10

Para usar reduce() en Python necesitamos importar la función desde la utilidad functools.

En nuestro caso usamos reduce() para sumar todos los items de un iterable de números enteros entre 0 y 4: 0 + 1 + 2 + 3 + 4.

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

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay