The focus of this part is an area of problems where scoping in Python is misunderstood. Usually, when we have global variables (okay, I’ll say it because I have to - global variables are bad), Python understands it if we access them within a function:
"The first misconception is that Python, being an interpreted language (which is awesome, I think we can all agree), is executed line-by-line. In truth, Python is being executed statement-by-statement. "
I have to admit I made a mistake, and your comment was valid ... The third code snippet should call 'foo()' then call 'print(bar)' ... And it turns out that bar is modified to [42, 0] (test on both Python-2 and 3).
The first misconception is that python is an interpreted language. Python is a compiled language just like Java. Even when you run a code in the "interpreter", this code is actually compiled to byte code and the byte code is then executed in a virtual machine!