Vai al contenuto principale
๐Ÿ”’ Modalitร  anteprima. Le prime quindici lezioni di Foundations sono gratuite; questa รจ Pro. Avvia un trial di 7 giorni per sbloccare l'editor, i suggerimenti AI e il resto del programma. Carta richiesta, disdici in qualsiasi momento dalla Dashboard.Avvia trial di 7 giorni โ†’
โšก
โ† Corsiโ€บSenior Deep-DivesModule 6 ยท FAANG-2026 deep divesโ€บfunctools.partial vs lambda โ€” closure timingpredict113 / 161
+150 XP
Compito๐ŸŒ shown in EN
๐Ÿ“ **Task:** Predict the exact output. \`mul(a, b, c)\` multiplies three numbers. \`double = partial(mul, 2)\` freezes \`a=2\`. \`with_c = partial(mul, c=10)\` freezes \`c=10\` โ€” but watch what happens when the caller ALSO passes \`c=99\`. Then five lines later: list of lambdas vs list of partials over the same loop. Which one captures correctly? ๐Ÿ“‹ Implement the function above. Tests run automatically. ๐Ÿ’ก **Hint:** Re-read the theory if you get stuck.
Predici output

Leggi il codice attentamente

from functools import partial


def mul(a, b, c):
    return a * b * c


double = partial(mul, 2)
print(double(3, 4))

with_c = partial(mul, c=10)
print(with_c(2, 3))
print(with_c(2, 3, c=99))


def show(i):
    return i


funcs_lambda = [lambda: i for i in range(3)]
funcs_partial = [partial(show, i) for i in range(3)]

print([f() for f in funcs_lambda])
print([f() for f in funcs_partial])

Cosa stamperร  il programma? Scrivi qui: