New submission from Philip Lee: There example code here becomes invalid https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result >>> squares = [] >>> for x in range(5): squares.append(lambda: x**2)
>>> squares [<function <lambda> at 0x01FB7A08>, <function <lambda> at 0x01F82390>, <function <lambda> at 0x01FBA3D8>, <function <lambda> at 0x01FBA420>, <function <lambda> at 0x01FBA468>] >>> There returned value is a List of lambda functions, not numbers ---------- assignee: docs@python components: Documentation messages: 291353 nosy: docs@python, iMath priority: normal severity: normal status: open title: Example code becomes invalid for "Why do lambdas defined in a loop with different values all return the same result?" type: enhancement versions: Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30023> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com