枚举

#  枚举
# enumerate枚举,对于一个可迭代的(iterable)/可遍历的对象(如列表、字符串),
# enumerate将其组成一个索引序列,利用它可以同时获得索引和值。
l = [5,'ni',6,'ow',9,5,6,]
for i  in enumerate(l):
    print(i)
# (0, 5)
# (1, 'ni')
# (2, 6)
# (3, 'ow')
# (4, 9)
# (5, 5)
# (6, 6)
for i  in enumerate(l,100):
    print(i)
    # (100, 5)
    # (101, 'ni')
    # (102, 6)
    # (103, 'ow')
    # (104, 9)
    # (105, 5)
    # (106, 6)

# Process finished with exit code 0
help(len)
#len(obj, /)
    # Return the number of items in a container.



l = 'nihaomehelleo'
for i in enumerate(l,1):
    print(i)

 

posted @ 2020-07-17 15:16  XuanchenLi  阅读(115)  评论(0编辑  收藏  举报