Modulo operator in Python

后端 未结 5 1931
無奈伤痛
無奈伤痛 2020-11-27 20:16

What does modulo in the following piece of code do?

from math import *
3.14 % 2 * pi

How do we calculate modulo on a floating point number?

5条回答
  •  無奈伤痛
    2020-11-27 20:41

    Same thing you'd expect from normal modulo .. e.g. 7 % 4 = 3, 7.3 % 4.0 = 3.3

    Beware of floating point accuracy issues.

提交回复
热议问题