a(*{q':'qq'}),为什么只有打印键

2024-09-30 02:29:16 发布

您现在位置:Python中文网/ 问答频道 /正文

def a(*x):
    print x

a({'q':'qqq'})
a(*{'q':'qqq'})#why only print key.

回溯:

^{pr2}$

Tags: keyonlydefprintwhypr2qqq
3条回答

这就是字典转换成序列的方式。在

元组(字典)=元组(字典.keys())

出于同样的原因

for x in dictionary:

为x指定键,而不是对

在函数调用中的表达式前面使用*将迭代表达式的值(在本例中是dict),并使迭代中的每个项成为函数调用的另一个参数。在Python中迭代dict会产生键(无论好坏)。在

调用函数时,listdict前使用星号将作为位置参数传入。在

例如:

>>> a(*('test', 'testing'))
('test', 'testing')

>>> a(*{'a': 'b', 'c': 'd'})
('a', 'c')

相关问题 更多 >

    热门问题