[Tutor] Advice for my function, isPrime(n), please
Terry Carroll
carroll at tjc.com
Mon Jul 21 22:42:39 CEST 2008
On Mon, 21 Jul 2008, Daniel Sarmiento wrote:
> What about the following function?
>
> if x == 0:
> return False
> return True
I don't like it, myself. You have multiple points of exit, and, yes, you
can see that the fallthough is only executed if the condition is not met,
but it makes you do a double-take when reading it.
If you insist on having the conditional, this is clearer:
if x == 0:
return False
else:
return True
I'd rather have the condition test for truth, though:
if x != 0:
return True
else:
return False
But that leads to what you don't like anyway, which I think is your best
solution:
return x != 0
More information about the Tutor
mailing list