Python:[E,] ** F是什么意思?

时间:2019-11-06 18:10:54

标签: python dictionary syntax

来自dict.update()文档字符串:

Docstring:
D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.

[E, ]**F是什么意思?

1 个答案:

答案 0 :(得分:0)

update可以接受现有字典(或键/值对的可迭代)作为其可选的位置参数,以及其他显式键/值对作为关键字参数。

例如:

>>> d = {'a': 1}
>>> e = {'b': 2}
>>> d.update(e, c=3)  # dict positional argument
>>> d
{'a': 1, 'b': 2, 'c': 3}
>>> d.update([('d', 4), ('e', 5)], f=6)  # iterable positional argument
>>> d
{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6}
>>> d.update(g=7)  # no positional argument
>>> d
{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7}