首页 > 编程语言 > 详细

Python enumerate

时间:2019-05-27 13:44:05      阅读:95      评论:0      收藏:0      [点我收藏+]
"""
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]), ...
    """
seasons = [Spring, Summer, Fall, Winter] # The enumerate object yields pairs containing a count (from start, which defaults to zero) and a value yielded by the iterable argument.
var = list(enumerate(seasons))
print(var) # [(0, ‘Spring‘), (1, ‘Summer‘), (2, ‘Fall‘), (3, ‘Winter‘)]

var =  list(enumerate(seasons, start=1)) # defaults to zero
print(var) #[(1, ‘Spring‘), (2, ‘Summer‘), (3, ‘Fall‘), (4, ‘Winter‘)]

 

Python enumerate

原文:https://www.cnblogs.com/pickKnow/p/10930246.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!