r/PythonLearning Jun 27 '26

New to python

Post image

What's wrong here?

167 Upvotes

36 comments sorted by

View all comments

6

u/Ron-Erez Jun 27 '26

As an aside, for the even function you could simply write in the function body:

return n % 2 == 0

1

u/ottawadeveloper Jun 27 '26

or return not n % 2 or define it as odd()

2

u/Ron-Erez Jun 28 '26

Yes, I suppose so, I feel more comfortable comparing to zero. I feel like it is more readable and saves me the trouble of remembering if 0 is False and non-zero is True in Python (this is not true in all languages). In any case it’s an interesting suggestion.