I'm currently studying python from http://www.sololearn.com/Play/Python and I'm having trouble understanding why this code works.
if x == 0:
return not is_even(x)
is_even's base case resolves to
not is_even(x), the value
True will be a part of the expression returned by
is_odd. The question is how many times will that
True value be negated. By tracing the calls you can see it will be negated an even number of times, and hence "retain" its truthiness, when
x is odd [e.g.:
(not (not (not (not True)))) ==
True] and an odd number of times, and hence "lose" its truthiness, when
x is even [e.g.:
(not (not (not True))) ==
False]. There's probably some term from logic that names this general property of multiple negation.