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" <>
To: "" <>
Cc: "Michael Dotolo" <>
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):

out put is
but if you call i again


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 .


docs mailing list --
To unsubscribe send an email to
Member address:

-- <br>Anthony Flury<br>