- len
返回列表中元素的个数,同样适用于元组、字典、集合、字符串
def len(*args, **kwargs): # real signature unknown""" Return the number of items in a container. """pass
>>> _str = "1234567890">>> len(_str)10>>> _tuple = tuple(_str)>>> len(_tuple)10>>> _list = list(_str)>>> len(_list)10
- zip
返回多个可遍历变量组合后的元组列表
class zip(object):"""zip(iter1 [,iter2 [...]]) --> zip objectReturn a zip object whose .__next__() method returns a tuple wherethe i-th element comes from the i-th iterable argument. The .__next__()method continues until the shortest iterable in the argument sequenceis exhausted and then it raises StopIteration.
>>> s1 = "12345">>> s2 = "67890">>> for i, j in zip(s1, s2):... print(i, j)...1 62 73 84 95 0
- enumerate
用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中
class enumerate(object):"""Return an enumerate object.iterablean object supporting iterationThe enumerate object yields pairs containing a count (from start, whichdefaults to zero) and a value yielded by the iterable argument.enumerate is useful for obtaining an indexed list:(0, seq[0]), (1, seq[1]), (2, seq[2]), ..."""
>>> _str = "1234567890">>> for i, e in enumerate(_str):... print(i, e)...0 11 22 33 44 55 66 77 88 99 0
引用:
[1]. https://blog.csdn.net/eacxzm/article/details/79778769
[2]. https://www.cnblogs.com/wzwpython/p/11549239.html
