How does python for get the number of current loops?

Source: Internet
Author: User

How does python for get the number of current loops?

From: http://markmail.org/message/ryfven2i75kgsrsm

Enumerate is a new built-in function in Python 2.3. Its English description is as follows:

Enumerate (iterable)

Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration. the next () method ofthe iterator returned by enumerate () returns a tuple containing acount (from zero) and the corresponding value obtained from
Iteratingover iterable. enumerate () is useful for obtaining an indexed series :( 0, seq [0]), (1, seq [1]), (2, SEQ [2]),... new in version 2. 3. this function is especially suitable for a for loop, and can be used when we need both counts and elements. For example, there is a string array that needs to be printed in one row, and the count is added before each row, starting from 1.

S = ['abc', 'This is a test', 'Hello, python']

For I, line in enumerate (s ):

Print I + 1, line

Related Article

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.