This question already has answers here:
What is the result of % in Python?
(20个答案)
三年前关闭。
当我用python计算除法的其余部分时,得到的答案如下:
>>> 12,121123123 % 10
(12, 3)
>>> 12,333434 % 5
(12, 4)
>>> 14,54 % 4
(14, 2)

最佳答案

14,54不是十进制数。它是一个包含整数1454的二元元组。
If you want to specify a decimal number, you have to use the decimal point .:

>>> 12.121123123 % 10
2.1211231230000003
>>> 12.333434 % 5
2.3334340000000005
>>> 14.54 % 4
2.539999999999999

Otherwise, your code is equivalent to this:
>>> (12, 121123123 % 10)
(12, 3)
>>> (12, 333434 % 5)
(12, 4)
>>> (14, 54 % 4)
(14, 2)

关于python - python中除法的其余部分,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39290819/

10-15 13:08