yes, the last variable in the loop is still available outside of the loop, that is often used together with some filtering. It is a 'known' thing.
Your last paragraph makes not very much sense. Python will still clean up the storage for the variable after it goes out of scope.
On Sun, Mar 6, 2022, at 6:00 PM, Ali Arslan wrote:
Hi we just noticed there is a potential bug in for loop
variable assignment in for loop. variable must unset after the block end at least in other programming language they do but in python 3 last assignment still exist sorry for my bad English but I can tell you with an example
for i in range(3): print(i)
out put is 0 1 2 but if you call i again print(i)
I don't know it is by purpose for some reason but I haven't seen it in any source so most of the programmers don't handle this situation . this situation can cause over ram usage and it might effect program's efficacy and optimization in large scale programs such as games or data processing if programmers don't handle this situation .
Thanks Ali ARSLAN _______________________________________________ docs mailing list -- email@example.com To unsubscribe send an email to firstname.lastname@example.org https://mail.python.org/mailman3/lists/docs.python.org/ Member address: email@example.com