python 3's adoption

Terry Reedy tjreedy at udel.edu
Thu Jan 28 19:20:02 CET 2010


On 1/28/2010 3:37 AM, Paul Rubin wrote:
> Jonathan Gardner<jgardner at jonathangardner.net>  writes:
>> If you're going to have statements, you're going to need the null
>> statement. That's "pass".
>
> Why?  Expressions are statements, so you could just say "pass" (in
> quotes, denoting a string literal), or 0, or None, os anything else like
> that, instead of having a special statement.

As Python is currently compiled, you are right, pass is not needed.
A string becomes the doc attribute, and becomes local var 0, but 0 is 
just ignored. I actually expected a load_const but that is now optimized 
away. I am not sure this was always true. Perhaps 'pass' is easier than 
'0' for mewcomers reading the tutorial, but I have no data.

 >>> def f(): ''

 >>> def g(): pass

 >>> def h(): 0

 >>> from dis import dis
 >>> dis(f)
   1           0 LOAD_CONST               1 (None)
               3 RETURN_VALUE
 >>> dis(g)
   1           0 LOAD_CONST               0 (None)
               3 RETURN_VALUE
 >>> dis(h)
   1           0 LOAD_CONST               0 (None)
               3 RETURN_VALUE
 >>> f.__doc__
''
 >>> g.__doc__
 >>>

Terry Jan Reedy




More information about the Python-list mailing list