return statement in functions

Carl Banks imbosol at aerojockey.invalid
Tue Dec 23 18:19:40 EST 2003


Francis Avila wrote:
> 
> 
> 
> hokiegal99 wrote in message
> <93f5c5e9.0312221718.23e42dac at posting.google.com>...
>>I was told earlier (w/o explanation) that functions should return
>>something. I was under the impression that it was OK with Python to
>>leave the return statement off.
> 
> Functions return something in Python, by definition.  If you leave the
> return statement off, Python inserts an implicit 'return None' to the end of
> the text of your function.


It seems that Python inserts the implicit "return None" even if you do
return a value.


Python 2.2.3c1 (#12, May 27 2003, 21:32:04) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def a(): 
...     return 1
... 
>>> import dis
>>> dis.dis(a)
          0 SET_LINENO               1

          3 SET_LINENO               2
          6 LOAD_CONST               1 (1)
          9 RETURN_VALUE        
         10 LOAD_CONST               0 (None)
         13 RETURN_VALUE        
>>> 


today's-trivia-tidbit-brought-to-you-by-truly yr's


-- 
CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon




More information about the Python-list mailing list