"None" and "pass"
Chris Angelico
rosuav at gmail.com
Mon Feb 5 15:48:07 EST 2018
On Tue, Feb 6, 2018 at 6:47 AM, Alain Ketterlin
<alain at universite-de-strasbourg.fr.invalid> wrote:
> ram at zedat.fu-berlin.de (Stefan Ram) writes:
>
>> A participant of my Python course asked whether one could
>> also use "None" instead of "pass". What do you think?
>>
>> def f():
>> pass
>>
>> can also be written as
>>
>> def f():
>> None
>>
>> . Is there any place where "None" could not be used
>> instead of "pass"?
>
> No, an expression is always a valid statement:
>
> https://docs.python.org/3.6/reference/simple_stmts.html
>
> Use None, or 42+0, or 1+1+1+1+1+1+1+1+1, or whatever you want (that does
> not have any side-effect and/or throw an exception). And be fired right
> after your first code review.
>
As one special case, I would accept this sort of code:
def f():
...
(three dots representing the special value Ellipsis)
It's a great short-hand for "stub".
Otherwise, though, an expression that isn't used (like putting "1+1"
on a line on its own) should normally fail a code review.
ChrisA
More information about the Python-list
mailing list