Python even/odd checks: Using truthiness instead of == 0

Python even/odd checks: Using truthiness instead of == 0

Python trick: 0 is falsy, 1 is truthy.

Use this for even/odd checks:

if n % 2:
    print('Odd!')   # remainder is 1 (truthy)
else:
    print('Even!')  # remainder is 0 (falsy)

No need for “if n % 2 == 0” — just use the truthiness!