如何在Python中计算mod b?


Answers:





25

mod = a % b

这会将的结果存储a mod b在变量中mod

没错,15 mod 4是3,这正是python返回的内容:

>>> 15 % 4
3

a %= b 也有效。



5

我认为您没有完全掌握模数。a % ba mod b只是表示模数的两种不同方式。在这种情况下,python使用%。不,15 mod 4不是115 % 4 == 15 mod 4 == 3


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.