开发者

The % function in Python [duplicate]

开发者 https://www.devze.com 2023-03-28 08:18 出处:网络
This question already has answers here: What is the result of % in Python? (20 answers) Closed 9 years ago.
This question already has answers here: What is the result of % in Python? (20 answers) Closed 9 years ago.

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.


  1. 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.
  2. Python % is used in two places, one is mathematical (the modulo operator), and the other has to do with formatting text. I'm going to assume "counting eggs" means the math way.
  3. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号