python 语法 dict(name=name) 是什么?

what's this python syntax dict(name=name)?

我在 the srapy documentation 中遇到过这种语法。

>>> abc = ['a', 'b', 'c']
>>> dict(abc=abc)
{'abc': ['a', 'b', 'c']}

the python dict documentation中似乎没有提到这个语法。这个语法叫什么?

这个使用keyword arguments.

大致相当于:

def make_dict(**kwargs):
    return kwargs

在你的情况下,

abc = ['a', 'b', 'c']
dict(abc=abc)

表示:

dict(abc=['a', 'b', 'c'])

等同于:

{'abc': ['a', 'b', 'c']}

没什么特别的,dict() 可以接受关键字参数和位置参数。您可以阅读 docs on dict().

因此在您的代码片段中 dict() 只需采用单个关键字参数。