[Python-ideas] Python docs page: In what ways is None special

C Anthony Risinger c at anthonyrisinger.com
Tue Jul 24 00:51:51 EDT 2018


On Jul 23, 2018 8:43 PM, "Chris Barker - NOAA Federal via Python-ideas" <
python-ideas at python.org> wrote:


> Procedures return None
> ==================
>>>> a = [3,1,2]
>>>> b = a.sort()
>>>> a, b
> ([1, 2, 3], None)

This is less about None than about the convention that mutating
methods return None. Maybe that discussion belongs elsewhere.


> None is default return value
> =====================
>>>> def fn(): pass
> ...
>>>> fn() # No response!
>>>> print(fn()) # Here's why.
> None

Yup.


I believe these two are related and an artifact of how code/function
objects always leave *something* on TOS/top-of-stack.

IIRC even module objects have a discarded "return value" (in CPython at
least). This internal, unseen, and very-much-special-syntax-worthy value,
is None other.

-- 

C Anthony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180723/76bd2061/attachment.html>


More information about the Python-ideas mailing list