0
In recursion, what does this statement mean..'return not'?
Here is a code: def is_even(x): if x==0: return True else: return is odd_(x-1) def is_odd(x) return not is_even(x). print(is_odd(17)) yields True. Now,i understand the whole code till the point of 'return not'. What does it mean exactly? And how is it related to the output?
3 Answers
+ 4
I've done extensive handtracing on this. In case you need it.
https://www.sololearn.com/Discuss/1333646/?ref=app
+ 1
not inverts a boolean
True -> False
False -> True
0
Because it returns a boolean, return not will return opposite of it's boolean it returns. if
is_even(x) returns False, not converts it to True and vise versa.