> On 12/12/2011 01:38 AM, Pete O'Connell wrote: >> Hi I have been writing python code for a while now and I never return >> anything within any of my functions, I just (eg.) print stuff or make >> directories or update a log or what have you. When I look at other >> people's code they are always returning in their functions and I was >> wondering if someone could give me an example of when I would absolutely >> have to return something. The thing I don't like about returning is that >> when I unindent a function and try to run the code to inspect parts of >> it for debugging I always have to alter the code so as not to get the >> "return not inside a function error", so I will change the word >> "return" to "print" and in many cases that's the way I leave it. Anyone >> have any thoughts on this?
I don't think recursion would work very well without return values. For a simple example: def factor(a): if a == 0: return 1 else: return a * factor(a-1) This isn't a very good way to handle factorization, but it shows recursion somewhat well. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor