[Tutor] Find out if a number is even or not
alan.gauld at freenet.co.uk
Sun Oct 17 09:03:57 CEST 2004
> def isEven1(n): return not n&1
> def isEven2(n): return n % 2 == 0
> def isEven3(n): return n % 2 and 'Odd' or 'Even'
Since the last is doing something quite different
could you try:
def isEven4(n): return n%2 and False or True
Which makes it closer to the others. I'd still expect it to
be slower but I wonder whether it closes the gap in any way?
More information about the Tutor