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?

4th Jul 2018, 8:54 AM
Benard Watta
Benard Watta - avatar
3 Answers
+ 4
I've done extensive handtracing on this. In case you need it. https://www.sololearn.com/Discuss/1333646/?ref=app
4th Jul 2018, 10:41 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
not inverts a boolean True -> False False -> True
4th Jul 2018, 9:06 AM
TurtleShell
TurtleShell - avatar
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.
4th Jul 2018, 12:03 PM
Seb TheS
Seb TheS - avatar