Many thanks for this quick answer.
I unfortunatly misread the tutorial (edx Course CS1301xII, Computing in Python 
II: Control Structures)
concerning scope insofar as a NameError arises if a variable is accessed which 
was not created inside
the control structure.
Marcus.

-----Ursprüngliche Nachricht-----
Von: Tutor [mailto:tutor-bounces+marcus.luetolf=bluewin...@python.org] Im 
Auftrag von Alan Gauld via Tutor
Gesendet: Samstag, 18. Mai 2019 12:34
An: tutor@python.org
Betreff: Re: [Tutor] simple question about scope

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


---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to