全局变量与局部变量
全局变量与局部变量调用 name = "你好" def weihu(): name = "天才" def kelian(): global name name = "帅哥" kelian() print(name) print(name) weihu() print(name) 结果: 你好 天才 帅哥 更换关键字:nolocal 赋值到上一个函数调用 name = "你好" def weihu(): name = "天才" def kelian(): nonlocal name # name=帅哥赋值给name=”天才 name = "帅哥" kelian() print(name) print(name) weihu() print(name) 结果: 你好 帅哥 你好