全局变量与局部变量
局部变量只在函数里起作用,全局变量在整个函数里起作用
def logger (): '日志功能' pass def home (): logger() print('home') def index(): logger() print('index')
函数与调用函数
name='cat' def change_name(): name='dog' print('my name is ',name) change_name()
修改全局变量用 global ...
name='cat' def change_name(): global name name='dog' print('my name is ',name) change_name()