UserLinux chooses Python as "interpretive language" of choice

Peter Otten __peter__ at web.de
Sun Dec 21 10:23:29 CET 2003


Jarek Zgoda wrote:

> Anyway, isn't that function always returns value, even without explicit
> "return" statement?

>>> import dis
>>> def f():
...     return 123
...
>>> dis.dis(f)
  2           0 LOAD_CONST               1 (123)
              3 RETURN_VALUE
              4 LOAD_CONST               0 (None)
              7 RETURN_VALUE
>>> def g():
...     raise Exception
...
>>> dis.dis(g)
  2           0 LOAD_GLOBAL              0 (Exception)
              3 RAISE_VARARGS            1
              6 LOAD_CONST               0 (None)
              9 RETURN_VALUE
>>> def h(): pass
...
>>> dis.dis(h)
  1           0 LOAD_CONST               0 (None)
              3 RETURN_VALUE
>>>

So Python always appends a 

return None

statement at the end of a function.
Of course that doesn't mean that it will be executed.

Peter





More information about the Python-list mailing list