As per question. I know that it does the same thing as number % 5 == 0, but I don't understand it. Can anyone kindly give an explanation for it?
Asked
Active
Viewed 358 times
-3
David Ferenczy Rogožan
- 23,966
- 9
- 79
- 68
12johnny
- 71
- 2
- 8
-
What have you tried to answer your own question? Python is an interpreted language. Start at the interpreter and type some stuff in. Start with `number = 23` (or whatever), then type `number % 5`. Then type `not number % 5` etc. See if you can noodle it out. Also check out tutorials on '%' and 'boolean logic'. – RobertB Oct 29 '15 at 17:20
-
I think its just personal taste. On my machine its marginally faster by 15% but that sort of thing is easily lost in the noise. – tdelaney Oct 29 '15 at 17:25
1 Answers
0
Any number other than 0 is True so say 3%5 = 3 which is True and not True is False. So the only time it can be True is if number % 5 == False or 0 because not False is True.
or
number % 5 == 0 = False == False = True
not(number % 5) = not False = True
If that doesn't make sense I can try to explain it another way.
SirParselot
- 2,640
- 2
- 20
- 31