python3 built-in function enumerate
I. Introduction:
This function is literally enumeration, include mean, for a data object to be traversed (e.g., list, string, or tuples) as a combination index sequence,
while the data lists and the subscript data, which is generally used in a for loop, the index values may be obtained and the corresponding data objects simultaneously. As described for the following example:
II Syntax:
the enumerate (Iterable, Start)
Iterable: iterables (list of tuples, dictionaries, iterator, string, etc.)
STAT: starting value of the sequence index
Note: This built-in functions common language for loop
III example 1:
1 a = ['zero','one','two','three','four','five','six','seven','eight','nine','ten'] 2 for index,i in enumerate(a): 3 print(index,i) 4 # 0 zero 5 # 1 one 6 # 2 two 7 # 3 three 8 # 4 four 9 # 5 five 10 # 6 six 11 # 7 seven 12 # 8 eight 13 # 9 nine 14 # 10 ten
Example 2:
1 b = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] 2 for index,i in enumerate(b,1): 3 print("星期%d:%s"%(index,i)) 4 5 # 星期1:Monday 6 # 星期2:Tuesday 7 # Week. 3: catalog on Wednesday . 8 # weeks. 4: catalog on Thursday . 9 # weeks. 5: catalog on Friday 10 # weeks. 6: Saturday . 11 # Week 7: Sunday