2024-05-19 17:08:25 发布
网友
我有以下代码:
def fun(a, b, c): print(a, b, c) d = {'a':2, 'b':4, 'c':10} fun(**d)
此代码打印2, 4, 10。我想知道为什么只打印字典值而不打印键
2, 4, 10
使用*表示键,使用**表示值,如下所示
要在函数或方法参数中传递字典,请使用**kwargs
def fun(**kwargs): print kwargs #< this prints the dictionary with it's keys d = {'a':2, 'b':4, 'c':10} fun(**d)
使用*表示键,使用**表示值,如下所示
要在函数或方法参数中传递字典,请使用**kwargs
相关问题 更多 >
编程相关推荐