将全局变量可以在函数体内进行修改
global + 全局变量名
不建议
使用global
对全局变量进行修改数字
字符串
空类型
布尔类型
的声明列表和字典
的全局变量不需要global进行声明# coding:utf-8
name = 'dewei'
age = 33
def test():
print(name)
test()
def test1():
name = '小慕'
print('函数体内', name)
test1()
print('函数体外', name)
def test3():
age = 33
print(age)
test3()
# print(age)
def test4(a):
a = 10
test4(name)
print(name)
def test5():
global name
global age
name = 10
age = 10
test5()
print(name)
print(age)
test_dict = {'a': 1, 'b': 2}
def test6():
test_dict['c'] = 3
test_dict.pop('a')
test6()
print(test_dict)