标签:glob lob 需要 不用 war 函数返回值 字典 global 变量
>>> def fun(a, b, *args, **kwargs): ... """可变参数演示示例""" ... print "a =", a ... print "b =", b ... print "args =", args ... print "kwargs: " ... for key, value in kwargs.items(): ... print key, "=", value ... >>> fun(1, 2, 3, 4, 5, m=6, n=7, p=8) # 注意传递的参数对应 a = 1 b = 2 args = (3, 4, 5) kwargs: p = 8 m = 6 n = 7 >>> >>> >>> >>> c = (3, 4, 5) >>> d = {"m":6, "n":7, "p":8} >>> fun(1, 2, *c, **d) # 注意元组与字典的传参方式 a = 1 b = 2 args = (3, 4, 5) kwargs: p = 8 m = 6 n = 7 >>> >>> >>> >>> fun(1, 2, c, d) # 注意不加星号与上面的区别 a = 1 b = 2 args = ((3, 4, 5), {‘p‘: 8, ‘m‘: 6, ‘n‘: 7}) kwargs: >>> >>>
局部变量
全局变量
总结:
全局变量
global
进行声明,否则出错强龙不压地头蛇
总结2:
标签:glob lob 需要 不用 war 函数返回值 字典 global 变量
原文地址:https://www.cnblogs.com/liu-wang/p/8976203.html