From 714fb14a211eb162016f73c963f4d2bc87fb9d28 Mon Sep 17 00:00:00 2001 From: Alok Menghrajani <441307+alokmenghrajani@users.noreply.github.com> Date: Mon, 24 Feb 2025 09:18:07 +0100 Subject: [PATCH] Clarify how you would end up with None in programming.rst Assigning `y.sort()` to a variable clarifies why you would end up with a `None`. --- Doc/faq/programming.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index 776bab1ed5b779..5b9b0c34d42f39 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -481,9 +481,9 @@ object, whereas superficially similar operations (for example ``y = y + [10]`` and :func:`sorted(y) `) create a new object. In general in Python (and in all cases in the standard library) a method that mutates an object will return ``None`` to help avoid getting the two types of operations confused. So if you -mistakenly write ``y.sort()`` thinking it will give you a sorted copy of ``y``, -you'll instead end up with ``None``, which will likely cause your program to -generate an easily diagnosed error. +mistakenly write ``z = y.sort()`` thinking ``z`` is a sorted copy of ``y``, +you'll instead end up with ``z`` being ``None``, which will likely cause +your program to generate an easily diagnosed error. However, there is one class of operations where the same operation sometimes has different behaviors with different types: the augmented assignment