0
How does this code work? (break down the code)
(from code challenge) https://code.sololearn.com/chFru359X9d3/?ref=app
4 Antworten
+ 1
Python is not C
While loops don't have a scope of their own
The python scopes are
Built-in
Global
Enclosed (functions)
Local (nested functions)
+ 2
It enters the infinite loop (while True)
First iteration: for n in 0...9 it does nothing
At the end of the for loop n is 9
The break statement breaks the while loop
print(n) prints n(=9)
0
But n wasn't declared outside while loop's scope, in fact it should belong to for loop's scope. And when the code block ends, shouldn't the variable be garbage collected?
0
Thanks, that's what I was looking for