字典可以用相同的方式通过**-operator 传递关键字参数 :
def parrot(voltage, state='a stiff', action='voom'): print("-- This parrot wouldn't", action, end=' ') print("if you put", voltage, "volts through it.", end=' ') print("E's", state, "!") d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"} parrot(**d) """ 列表或者元组通过 * 解压缩参数列表 """ print(list(range(3,6))) l = [3,6] # print(list(range(l))) print(list(range(*l))) # * 将一个整体的变量l解压缩为两个变量(3,6) # 需要接受三个连续的参数 def fun(a,b,c): print(a,end='-') print(b,end='-') print(c,end='-') fun(1,2,3) print() l1 = [6,5,4] fun(*l1) print() ''' * 解压缩字典 {'a':1,'b':2,'c':4} ==> a,b,c 可以使用 ** 解压字典的key参数 {'a':1,'b':2,'c':4} ==> a = 1,b = 2,c = 4 ''' d = {'a':1,'b':2,'c':4} print(*d) # * 只有key值 fun(*d) # ** 有k-v对 fun(**d)