Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialName:GoogleSearch orJonathan Sum
5,039 Pointsdef even_odd(num): # If % 2 is 0, the number is even. # Since 0 is falsey, we have to invert it with not.
return not num % 2 why there is a reutrn not here?
def even_odd(num):
# If % 2 is 0, the number is even.
# Since 0 is falsey, we have to invert it with not.
return not num % 2
2 Answers
Quentin Durantay
17,880 PointsNo, you have several values which are falsey by default for each programming languages, and other that are truthy. In all programming languages, 0 (the number zero) is always falsey. But in the precise case of this function even_odd you want the result 0 to give you back True, so you have to negate False to get back True.
Quentin Durantay
17,880 PointsYou want the function to give you back True when the number is even, that is the number % 2 = 0. The thing is, 0 is falsey in Python (like in all other languages), so you have to put not, so that when the result is 0, the function inverts False and give you True (because not False = True).
Name:GoogleSearch orJonathan Sum
5,039 Pointsdoes it mean not False is a int which is zero?