Python Forum

Full Version: where is this documented?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
the following code:

foo = {}.update(os.environ)
has a behavior that i have been unable to find documentation that describes (assuming import os has been done). does anyone know if such documentation exists and where that documentation can be found? i have PDF documentation for python version 3.5.2 but a reference in an HTML document of 3.4 or later should be good enough.
According to the documentation, the behavior is the same as foo = None.
(Feb-17-2018, 01:32 PM)Gribouillis Wrote: [ -> ]According to the documentation, the behavior is the same as foo = None.

my documentation (PDF letter format for 3.5.2) didn't give that information. maybe i need to switch back to the HTML documentation (been using PDF for 3+ years).
If you read carefully, typing pydoc3 dict.update in a terminal gives the same information.
yes, it sure does. i was not aware of this way to get python documentation.
If have a "cool" editor mouse over update Wink
[Image: dRd3Aj.jpg]
foo = {}.update(os.environ)
foo is None because the method update returns None.
You can do this technique with data types, which returns a new copy of them selfs if mutated (str does this).

It's the same pitfall like this:
sorted_list = [1,4,5,6,7,3,2].sort()
list.sort() makes an inline sort (mutating the object itself) and returns None.
i guess i am just used to methods that returned something useful. i did know about .sort but didn't think of it as another case. i usually use sorted(iterable).