This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: local var in "for v in iter" modify the uplevel var value.
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: r.david.murray, zaazbb
Priority: normal Keywords:

Created on 2016-09-09 02:15 by zaazbb, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg275233 - (view) Author: zaazbb (zaazbb) Date: 2016-09-09 02:15
eg:

s = 'aaa'
print(s)
for s in '111', '222', '333':
    print(s)
print(s)

the right result should be:
'aaa'
'111'
'222'
'333'
'aaa'

but, i got:
'aaa'
'111'
'222'
'333'
'333'

the local var in "for v in iter", modify the uplevel var value.
Is it wrong?
msg275234 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-09-09 02:20
No, that's the way python works.  A for loop does not have its own scope.
History
Date User Action Args
2022-04-11 14:58:36adminsetgithub: 72221
2016-09-09 02:20:14r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg275234

resolution: not a bug
stage: resolved
2016-09-09 02:15:37zaazbbcreate