Python Enumerate function usage

Source: Internet
Author: User

The enumerate dictionary is an enumeration, enumerated meaning.

The keyword enum in the C language is also an abbreviation for enumerate. In Python, the Enumerate method returns a enumerate type. Parameters are generally things that can be traversed, such as a list, a string, or something. This is said in the Python document: Enumerate (sequence, [start=0]) Return an enumerate object. Sequence must is a sequence, an iterator, or some other object which sup-ports iteration. The next () method of the iterator returned by enumerate () returns a tuple Containinga count (from start which defaults to 0) and the corresponding value obtained from iterating through iter-able.  Enumerate () is useful for obtaining an indexed series: (0, Seq[0]), (1, seq[1]), (2,seq[2]), .... For example:>>> for me, season in enumerate ([' Spring ', ' Summer ', ' Fall ', ' Winter ']): ... print i, Season0 Spring1 S Ummer2 Fall3 Winter I tried it, if the loop was changed to season in [' Spring ', ' Summer ', ' Fall ', ' Winter ']: Actually, it's OK, but enumerate will return an indexed thing, That I, that I, starting from 0, each plus one.

Python Enumerate function usage

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.