[Tutor] Find out if a number is even or not

Alan Gauld 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?

Alan g

More information about the Tutor mailing list