How to calculate a mod b in Python?

后端 未结 7 1262
迷失自我
迷失自我 2020-12-12 21:47

Is there a modulo function in the Python math library?

Isn\'t 15 % 4, 3? But 15 mod 4 is 1, right?

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 22:00

    I don't think you're fully grasping modulo. a % b and a mod b are just two different ways to express modulo. In this case, python uses %. No, 15 mod 4 is not 1, 15 % 4 == 15 mod 4 == 3.

提交回复
热议问题