Does the modulo operator work with floating point numbers?


#1

Question

In this exercise, the modulo operator is used with only integer numbers. Will it work with floating point numbers too?

Answer

Yes, the Python modulo operator will work with floating point numbers.


#2
>>> from math import pi
>>> def is_float(n):
    return n % 1 and True or False

>>> is_float(1)
False
>>> is_float(pi)
True
>>>