I've encounter this syntax in the srapy documentation .
>>> abc = ['a', 'b', 'c']
>>> dict(abc=abc)
{'abc': ['a', 'b', 'c']}
There doesn't seem to have this syntax mentioned in the python dict documentation . What is this syntax called?
This use keyword arguments .
It is roughly the same as:
def make_dict(**kwargs):
return kwargs
In your case,
abc = ['a', 'b', 'c']
dict(abc=abc)
means:
dict(abc=['a', 'b', 'c'])
which is the same as:
{'abc': ['a', 'b', 'c']}
There is nothing special, dict()
can take keyword arguments as well as positional arguments. You can read the docs on dict()
.
So in your code snippet dict()
just take single keyword argument.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.