The % function in Python [duplicate]
I'm working on the exercises in Learning Python the Hard Way and I am wondering what the % function does. I am getting the wrong answer when i count my eggs and hoping understanding this will help开发者_开发问答 me understand what I'm doing wrong.
- I can't really tell why your code is broken because you haven't shown anybody what your code is. Please post samples and links next time.
- Python
%
is used in two places, one is mathematical (themodulo
operator), and the other has to do with formatting text. I'm going to assume "counting eggs" means the math way. The modulo operator in
X % Y
means "Divide X by Y and give me the remainder." So:10 % 2 == 0
10 % 3 == 1
10 % 11 == 10
That is the the modulo operator
精彩评论