python 在函数中访问全局变量

python允许在函数中访问全局变量的值,但不允许在函数中修改全局变量的值。

In the last video, you saw that within a function, we can print a global variable’s value successfully without an error. This worked because we were simply accessing the value of the variable. If we try to change or reassign this global variable, however, as we do in this code, we get an error. Python doesn’t allow functions to modify variables that aren’t in the function’s scope.

猜你喜欢

转载自blog.csdn.net/linkequa/article/details/84928014
今日推荐