[Tutor] simple question about scope
marcus lütolf
marcus.luetolf at bluewin.ch
Sat May 18 04:20:20 EDT 2019
Dear experts
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.
However in for loops - also control structures - like in this
simple example:
for i in range(1,11):
sum = 0
sum += i
print(sum)
the print function "returns" the last number of range as
value of the variable sum created inside this for loop.
It should have raised a Name Error instead.
Could somebody please explain this discrepancy?
Marcus.
---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus
More information about the Tutor
mailing list