Python Enumerate () function----Enumeration

Source: Internet
Author: User

Describe

The enumerate () function is used to combine a data object that can be traversed (such as a list, tuple, or string) into an index sequence, while listing data and data subscripts, typically used in a for loop.

Python 2.3. The above version is available, 2.6 add the start parameter.

Grammar

The following is the syntax for the Enumerate () method:

Enumerate (sequence, [start=0])
Parameters
    • Sequence--a sequence, iterator, or other supporting iteration object.
    • Start-the subscript start position.
return value

Returns the enumerate (enum) object.

Instance

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))#Small label starting from 1[(1,'Spring'), (2,'Summer'), (3,'Fall'), (4,'Winter')]
Normal. forLoops>>>i =0>>> seq = [' One',' Both','three']>>> forElementinchseq: ...PrintI, Seq[i] ... i+=1... 0 One1 Both2three forcyclic use of enumerate>>>SEQ = [' One',' Both','three']>>> forI, ElementinchEnumerate (seq): ...PrintI, Element ... 0 One1 Both2 Three

Python Enumerate () function----Enumeration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.