Python中,%的运用

天啦Python要考试啦啥也不会,求路过朋友帮帮
123.45%3.2这个求余数运算是怎么算的?
还有这个
-17%4

掌握公式
a % b = a-(a//b)*b
所以
123.45 % 3.2 =1.85
-17%4 =3


123.45%3.2=1.849999999999996
-17%4=-1

%就是求一个数除以一个数的余数。

取余运算相当于以下函数表达:

def mod(a,b):
    while not 0<a<b:
        if a>0:
            a -= b
        else:
            a += b
    return a

print(mod(123.45,3.2))
print(mod(-17.5,4.10))