[New-bugs-announce] [issue44332] For Loop temporary variable scope should be local to For loop

Debasis Satapathy report at bugs.python.org
Mon Jun 7 00:56:39 EDT 2021


New submission from Debasis Satapathy <deb_ctc at yahoo.co.in>:

numbers = [1, 2, 3, 4, 5, 6, 7, 8]
for x in numbers:
    print(x)
print(x)

In the above code, print(x) statement should give error. Because x scope should be local to for loop only.
99% cases, developers will not use the temporary variable x outside of the for loop.
So x will keep on consuming memory always. So it is a bad usage of memory.
Ideally x memory should be free once for loop execution is completed.

----------
components: Library (Lib)
messages: 395246
nosy: deb_ctc
priority: normal
severity: normal
status: open
title: For Loop temporary variable scope should be local to For loop
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44332>
_______________________________________


More information about the New-bugs-announce mailing list