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) output 2 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
Hi Ali, 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. Regards, Simon 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)
output 2
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 -- docs@python.org To unsubscribe send an email to docs-leave@python.org https://mail.python.org/mailman3/lists/docs.python.org/ Member address: skelley@tty.cat
This isn't a bug, In other languages - loops form closed scopes (so that variables declared inside the loop don't exist outside). In Python for loops don't for closed scopes - variables are considered to all be at the function level and will only dissappear at the end of the function. Remember that for simple things like this - Python is heavily used across industry millions of times per day, so trivial things that look different are likely to be by design and are unlikely to be bugs. ------ Original Message ------ From: "Ali Arslan" <583831@csinow.edu> To: "docs@python.org" <docs@python.org> Cc: "Michael Dotolo" <mdotolo@csinow.com> Sent: Sunday, 6 Mar, 22 At 17:00 Subject: [docs] potential bug in python 3 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) output 2 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 -- docs@python.org To unsubscribe send an email to docs-leave@python.org https://mail.python.org/mailman3/lists/docs.python.org/ <https://mail.python.org/mailman3/lists/docs.python.org/> Member address: anthony.flury@btinternet.com -- <br>Anthony Flury<br>anthony.flury@btinternet.com
participants (3)
-
Ali Arslan
-
anthony.flury
-
Simon J.M. Kelley