On 18/05/2019 09:20, marcus lütolf wrote: > in learning the principles of Python I came across scope in the > control structure's section. > There I read the notion that variables createted inside a > control structute can't be seen or accessed from outside that > structure, Python would raise a Name Error.
I don't know which tutorial you are reading but that's just wrong. Names created inside functions are local to that function. Names created inside a module are local to that module (and rather confusingly referred to as global scope) Names created inside a class are local to that class. Names created inside a generator expression are local to that expression. That's pretty much all you need to know about python scoping. > However in for loops - also control structures - like in this > simple example: Control structures like for/while/if-else etc have no influence no name visibility. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor