return statement in functions
BW Glitch
bwglitch at hotpop.com
Mon Dec 22 21:45:54 EST 2003
hokiegal99 wrote:
> 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
All Python functions return None by default.
--
Glitch
-----BEGIN TF FAN CODE BLOCK-----
G+++ G1 G2+ BW++++ MW++ BM+ Rid+ Arm-- FR+ FW-
#3 D+ ADA N++ W OQP MUSH- BC- CN++ OM P75
-----END TF FAN CODE BLOCK-----
"I can suffer your treachery, Lieutenant ... but NOT your
incompetence! ... Treachery requires NO mistakes."
-- Megatron to Tarantulas, "Master Blaster"
More information about the Python-list
mailing list