python3.5 enumerate函数的解析及使用方法

# Author Richard_Kong
# !/usr/bin/env python
# --*-- encoding:utf-8 --*--
"""enumerate的使用方法"""
f = open('lyrics',encoding='utf-8')
# 可以打印出index
"""
    enumerate(iterable[, start]) -> iterator for index, value of iterable

    Return an enumerate object.  iterable must be another object that supports
    iteration.  The enumerate object yields pairs containing a count (from
    start, which defaults 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]), ...
上面是对函数的解释,输入参数:一个迭代对象 iterable,start 下标起始位置
返回是要一个enumerate对象,包括下标的计数(默认从0开始),和一个下标列表,seq[index]
"""
for index,line in enumerate(f,50):
    print(index,":::::",line.strip())

猜你喜欢

转载自blog.csdn.net/kokodudu/article/details/81505657