🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
* 作者:煮酒品茶 tea * 博客:http://www.zwhset.com http://cwtea.blog.51cto.com * 目前在京峰教育担任python讲师 #0、求商取余函数divmod() 在数学中, x 除以y 会得到两个值,一种是1.3 另一种是得到商和余数,divmod则为求商取余的函数 #1、函数原型 divmod(...) #提供x,y参数,得到一个元组对象(商,余) divmod(x, y) -> (quotient, remainder) #结果为((x-x%y)/y, x%y) 元组内第一个对象的求过程,第二个是余 Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x. #2、样例 ~~~ In [1]: divmod(10,3) Out[1]: (3, 1) In [2]: divmod(9,3) Out[2]: (3, 0) In [3]: divmod(12,4) Out[3]: (3, 0) In [4]: divmod(12,5) Out[4]: (2, 2) ~~~ x