Python enumerate() function

description##

The enumerate() function is used to combine a traversable data object (such as a list, tuple or string) into an index sequence, and list data and data subscripts at the same time. It is generally used in a for loop.

Python 2.3. and above are available, and 2.6 adds the start parameter.

grammar###

The following is the syntax of the enumerate() method:

enumerate(sequence,[start=0])

parameter###

return value###

Return an enumerate (enumeration) object.


Examples##

The following shows an example of using the enumerate() method:

>>> seasons =['Spring','Summer','Fall','Winter']>>>list(enumerate(seasons))[(0,'Spring'),(1,'Summer'),(2,'Fall'),(3,'Winter')]>>>list(enumerate(seasons, start=1)) #Subscripts start from 1
[(1,' Spring'),(2,'Summer'),(3,'Fall'),(4,'Winter')]

Ordinary for loop##

>>> i =0>>> seq =['one','two','three']>>>for element in seq:... print i, seq[i]... i +=10 one 1 two 2 three

for loop using enumerate

>>> seq =['one','two','three']>>>for i, element inenumerate(seq):... print i, element 
0 one 1 two 2 three

Recommended Posts

Python enumerate() function
Python function buffer
Python custom function basics
Join function in Python
Python built-in function -compile()
Python function basic learning
Python data analysis-apply function
Python Print print timer function
Python defines a function method
Python high-order function usage summary!
Python realizes online translation function
Python tornado upload file function
Python magic function eval () learning
Python implements image stitching function
Python high-order function usage summary!
Python telnet login function implementation code
Python| function using recursion to solve
How Python implements the mail function
Why doesn't Python support function overloading?
Is there function overloading in python
Learning Python third day one-line function
Python function definition and parameter explanation
Python ATM function implementation code example
Python implements AI face change function
Python realizes image recognition car function
Python implements ftp file transfer function
Python realizes udp transmission picture function
How Python implements the timer function
Python multithreading
Python CookBook
Python3 dictionary
Python3 module
python (you-get)
Python-lambda function
Python string
Python basics
Python descriptor
Python basics 2
Python exec
Python notes
How to run id function in python
Python3 tuple
CentOS + Python3.6+
Python advanced (1)
Python decorator
Python IO
Python multithreading
What is the id function of python
Python toolchain
What is an anonymous function in Python
Python3 list
Python overview
python introduction
Python analytic
Python basics
How does python call its own function
07. Python3 functions
Python basics 3
python3 realizes the function of mask drawing
Python multitasking-threads
Python functions