Python local vs global variables

前端 未结 4 1683
无人共我
无人共我 2020-12-01 21:52

I understand the concept of local and global variables in Python, but I just have a question about why the error comes out the way it is in the following code. Python execut

4条回答
  •  抹茶落季
    2020-12-01 22:06

    Python doesn't execute line by line in the function code you submitted. It has first to parse it as a bloc of execution. It decides if a variable is local or global depending if it is written at (function) local level. As it is the case, it decides that the variable is local, hence the error.

提交回复
热议问题