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 trial

Python Comparison Solution

Muhammad-Nasir Kori
Muhammad-Nasir Kori
385 Points

I'm confused about how the % is used in the division of numbers. Can someone please elaborate?

hi. i am having some confusion with the boolean. It seems as though it was used for the division. i thought that was the job of the forward slash? Can someone break down that part of the code for me? Thanks a lot.

1 Answer

Nemanja Savkic
Nemanja Savkic
17,418 Points

Hi,

I'm unable to watch the video at the moment but I will try and help.

That symbol is called Modulo and it returns the remaining of the division. 7%2 will return 1 because 7/2 is 3 and some more (1). 8%3 will return 2 but 8%2 will return 0, since 8/2 is 4 without remainder.

It's mostly used to check if a number is even or odd (n%2 - if it returns 0 its even, if it returns 1 it's odd. n%2 can't return any other value) but you can find it's usage in many other ways.

Hope I clarified it. Have fun!