Python 关键字 -- `global`
Less than 1 minute
用法
# 预先全局声明
current_date = datetime.datetime.now().strftime('%Y-%m-%d')
def a():
global current_date
current_date = '2024-09-05'
if __name__ == '__main__':
print(current_date)
# 输出 2024-09-03
a()
print(current_date)
# 输出 2024-09-05