Reputation: 689
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?
Upvotes: 2
Views: 341
Reputation: 23494
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.
Upvotes: 1
Reputation: 226346
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']}
Upvotes: 4