Python的dict.update的文档如下:
Help on method_descriptor:
update(...)
D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
[E,]**F
是什么意思?它们是两个单独的参数吗?如果是,为什么它们不以逗号分隔?
最佳答案
符号[E, ]**F
表示位置参数E
是可选的([ ]
内的所有参数都是可选的,即在方法声明中分配了默认值),并且它接受可变数量的关键字参数作为F
。 (这在文档中通常称为 **kwargs
)
在该方法中,F
将是一个 dict
,其中包含所有关键字参数作为键值对。
关于python - 如何阅读文档中的 D.update([E, ]**F) ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56427182/