Is % modulo different than / division?

In the solution, how does:

if number % 3 == 0:

Ensure that the number is divisible by 3, and not just ensure that the number is 3? Surely if I call:

by_three(9)

The function should return False, because 9 / 3 = 3, not 0. Yet when I tried this i got 729 as an output.

There’s clearly something I’m missing surrounding the == 0 part of the code but I’m not sure what?

2 Likes

this condition uses the modulo operator (%), which gives the remainder, which is different from division operator (/)

1 Like

Of course! I’m a tired idiot, thanks!