python变量作用域

 
1 def test():
2     c = 1
3     print a,b
4     print c
5 
6 if __name__ == "__main__":
7     a = 1;
8     b = 2;
9     test()

 test函数中的,a,b依然可以声明成功,并且成功打印结果,说明在编译时,并不检查函数的值是否已经声
 
原文地址:https://www.cnblogs.com/harveyaot/p/2975716.html