Python内置函数(四)---divmod和enumerate

divmod(a, b)

输入为两个实数,不能为负数,输出为元组,分别为除数和余数

| 信令 | 输出 |
| ---- | ---- | ---- |
| divmod(5,4) | (1,1) |
| divmod(4,5) | (0,4) |
| divmod(5.0,4.0) | (1.0,1.0) |
| divmod((1+2j),3) | TypeError |

enumerate(iterable, start=0)

输入为可迭代的对象,输出为一个迭代器。迭代器内容为输入对象的(index和元素数值)。start表示开始计数数值。

| 信令 | 输出 |
| ---- | ---- | ---- |
| enumerate(【1,2,3】) | <enumerate object at 0x0000000002961600> |
| list( enumerate(【1,2,3】)) | [(0, 1), (1, 2), (2, 3)] |
| list(enumerate([1,2,3],start=2)) | [(2, 1), (3, 2), (4, 3)] |

原文地址:https://www.cnblogs.com/Finding-bugs/p/14217002.html