Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Tip on the "Late Binding Closures" section

Open
#526 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
documentation

Research direction

Read the "Late Binding Closures" section, especially "What You Should Do Instead," and compare the proposed generator example with the existing explanations. Run the supplied create_multipliers() loop to verify the closure behavior. Done means the documentation accurately presents any valid alternative and includes a clear supporting example.

Written by the indexing model from the issue text.

Description

The two solutions in "What You Should Do Instead" are certainly correct, while there's another solution in that special case, one can simply change

return [lambda x : i * x for i in range(5)]

to

return (lambda x : i * x for i in range(5))

in other words, one can create a generator, rather than a list, to postpone the time when cell contents be evaluated. Actually, a more essential test code could be

for multiplier in create_multipliers():
    print multiplier.__closure__[0].cell_contents

FYI.

Dominant language
Batchfile
Stars
29.8k
Forks
5.9k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from realpython/python-guide

All issues in realpython/python-guide

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.