2024-09-30 02:29:16 发布
网友
def a(*x): print x a({'q':'qqq'}) a(*{'q':'qqq'})#why only print key.
回溯:
这就是字典转换成序列的方式。在
元组(字典)=元组(字典.keys())
出于同样的原因
for x in dictionary:
为x指定键,而不是对
在函数调用中的表达式前面使用*将迭代表达式的值(在本例中是dict),并使迭代中的每个项成为函数调用的另一个参数。在Python中迭代dict会产生键(无论好坏)。在
*
调用函数时,list或dict前使用星号将作为位置参数传入。在
list
dict
例如:
>>> a(*('test', 'testing')) ('test', 'testing') >>> a(*{'a': 'b', 'c': 'd'}) ('a', 'c')
这就是字典转换成序列的方式。在
元组(字典)=元组(字典.keys())
出于同样的原因
为x指定键,而不是对
在函数调用中的表达式前面使用
*
将迭代表达式的值(在本例中是dict),并使迭代中的每个项成为函数调用的另一个参数。在Python中迭代dict会产生键(无论好坏)。在调用函数时,
list
或dict
前使用星号将作为位置参数传入。在例如:
相关问题 更多 >
编程相关推荐