mirror of
https://github.com/python/cpython.git
synced 2025-09-30 04:15:43 +00:00
bpo-36715: Add usage note for dict.fromkeys() (GH-12974)
This commit is contained in:
parent
50fed0b64f
commit
da63b321f6
1 changed files with 4 additions and 1 deletions
|
@ -4254,7 +4254,10 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
|
||||||
Create a new dictionary with keys from *iterable* and values set to *value*.
|
Create a new dictionary with keys from *iterable* and values set to *value*.
|
||||||
|
|
||||||
:meth:`fromkeys` is a class method that returns a new dictionary. *value*
|
:meth:`fromkeys` is a class method that returns a new dictionary. *value*
|
||||||
defaults to ``None``.
|
defaults to ``None``. All of the values refer to just a single instance,
|
||||||
|
so it generally doesn't make sense for *value* to be a mutable object
|
||||||
|
such as an empty list. To get distinct values, use a :ref:`dict
|
||||||
|
comprehension <dict>` instead.
|
||||||
|
|
||||||
.. method:: get(key[, default])
|
.. method:: get(key[, default])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue