no side effects
holger krekel
pyth at devel.trillke.net
Wed Jan 8 10:00:31 EST 2003
"Martin v. L?wis" wrote:
> holger krekel wrote:
> > for i in [1,2,3]:
> > print i
> > i=3
> >
> > the for-loop will iteratively bind the (local) name to
> > 1, then 2, then 3. It never looks at the binding of
> > the name 'i'. With 'i=3' you only change the binding
> > of 'i' to the object '3' but the for-loop will blindly
> > change the binding again.
>
> This has nothing to do with namespaces: i is not local to the for loop,
> but might be global, or local to the function.
'i' might not be local but usually it is. When answering
newcomer questions i try to refrain from talking in language
lawyer details (as much as possible). I only tried to explain the
for-loop from the viewpoint of names bound to objects. I didn't
want to compare iteration protocols between python and C++ just
to explain that.
holger
More information about the Python-list
mailing list