Brian van den Broek schrieb:
If my original bit of code, the structure was like:
output_value = False if condition: output_value = True return output_value
Mine would be like yours if transformed to:
if condition: return True return False
Hi Brian! Do you mean, that condition is something which is True od False? And if condition is True you want to return True? And if condition is False you want to return False?
So why not simlpy:
return condition
?
Regards, Gregor
Hi Gregor,
why not indeed?
As I see what I've been blithering on about, there are two issues in the air: 1) single exit versus multiple exit functions, and 2) my seemingly entrenched tendency to overlook that I can do just what you point out.
The above was reply to Liam's:
I find multiple returns to be rather useful -
def isOdd(x):
if not x % 2: return False
return True
*If* one isn't doing what you suggest (through a dogged determination to fail to learn from the past, I imagine ;-), I still prefer the single exit point way I give above. But, as Guille pointed out to Liam, neither of these ways are needed when your way is available, too. So, I like my way of being foolish and inefficient better, given a commitment to foolish inefficiency ;-)
(FWIW, I did manage to start this thread with code where the condition was of the form "this try block doesn't raise an exception" so, unless using one of Tim's helpful suggestions, no function with a single line that returns would do.)
On the plus side, publicly getting the same style of correction multiple times in a few days greatly increases the chance that some of this might actually making it into my own practise!
So, thanks to all who've responded.
Best,
Brian vdB
_______________________________________________ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor