Following code explain how 'global' works in the distinction of global variable and local variable. var = 'Global Variable' print(var) def func1(): var = 'Local Variable' print(var) def func2(): print(var) def func3(): global var print (var) var = 'G…
val = 9 def test(flag): if flag: val = 1 else: print("test") return val if __name__ == '__main__': ret = test(0) print(ret) 运行如下: linux@linux-desktop:~$ python3.3 test.py fuckTraceback (most recent call last): File "test.py", line 10,…
In C, we cannot access a global variable if we have a local variable with same name, but it is possible in C++ using scope resolution operator (::). 1 #include<iostream> 2 using namespace std; 3 4 int x; // Global x 5 6 int main() 7 { 8 int x = 10;…