python divmod()和mod()、floordiv()的区别
divmod(self, other):定义当被 divmod() 调用时的行为,返回的值是一个元组:(a//b,a%b)
如:
divmod(7, 2)
(3, 1)
mod(self, other):定义取模算法的行为:%
如:
7% 2
1
floordiv(self, other):地除法,定义整数除法的行为://,返回值去掉小数
如:
7//2
3
divmod(self, other):定义当被 divmod() 调用时的行为,返回的值是一个元组:(a//b,a%b)
如:
divmod(7, 2)
(3, 1)
mod(self, other):定义取模算法的行为:%
如:
7% 2
1
floordiv(self, other):地除法,定义整数除法的行为://,返回值去掉小数
如:
7//2
3