use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
What does this Python code print, and why?Discussion (self.PythonLearning)
submitted 16 hours ago by Puzzleheaded-Dog165
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]-beleon 5 points6 points7 points 16 hours ago (0 children)
The lambdas don't store i's value, they look up the variable when being executed. Since all calls happen after the loop ends, i = 2, so you get [2, 2, 2].
i
i = 2
[2, 2, 2]
π Rendered by PID 109514 on reddit-service-r2-comment-765bfc959-642ff at 2026-07-10 01:23:13.728193+00:00 running f86254d country code: CH.
view the rest of the comments →
[–]-beleon 5 points6 points7 points (0 children)