return statement in functions

hokiegal99 hokiegal99 at hotmail.com
Mon Dec 22 20:18:35 EST 2003


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. Could someone enlighten me on why or
why not to use a return statement when defining functions? Below is
the bit of code I was told should return something:

def fs_object_count(path):
   file_count = 0
   dir_count = 0
   for root, dirs, files in os.walk(path):
      file_count += len(files)
      dir_count += len(dirs)
   print "Number of Files Examined: ", file_count
   print "Number of Folders Examined: ", dir_count
   print "Total Number of FS Objects:", file_count + dir_count




More information about the Python-list mailing list