Python built-in function enumerate ()

Source: Internet
Author: User

Enumerate () is a python built-in function.

1 Help (Enumerate)2Help onclassEnumerateinchModule Builtins:3 classenumerate (object)4Enumerate (iterable[, start]), iterator forIndex, value of Iterable5#enumerate (iterate variable [, start subscript]) returns the index and value of the iteration variable. (Note that dictionaries and collections can also be used, taking the position as an index)6Return an Enumerate object.  Iterable must is another object that supports iteration. The enumerate object yields pairs containing a count ( fromStart, which defaults to zero) anda value yielded by the iterable argument.7Enumerate isUseful forObtaining an indexed list:8(0, Seq[0]), (1, seq[1]), (2, seq[2]), ...9  Ten Methods defined here: One    A __getattribute__(Self, name,/) - Return getattr (self, name). -    the __iter__(Self,/) - Implement iter (self). -    - __new__(*args, **kwargs) fromBuiltins.type +Create and returnA new object. See Help (Type) foraccurate signature. -  + __next__(Self,/) A Implement Next (self). at   - __reduce__(...) -Return State information forPickling.

For an iterative iterable/of objects (such as lists, strings, tuples, dictionaries, and collections) that can be traversed.

Enumerate () is used to get a count in the for loop; enumerate () returns a enumerate object.

1  forIinchEnumerate ([1,2,3,4,5]):#Action on List2     Print(i)3     4(0, 1)5(1, 2)6(2, 3)7(3, 4)8(4, 5)9 Ten  forIinchEnumerate ((+)):#effect on the tuple One     Print(i) A      -(0, 1) -(1, 2) the(2, 3) -  -  forIinchEnumerate (' Help'):#function on string -     Print. IO +      -(0,'h') +(1,'e') A(2,'L') at(3,'P') -  -  forIinchEnumerate ({'name':'Zoe',' Age': 18}):#effect on dictionaries -     Print(i) -      -(0,'name') in(1,' Age') -  to  forIinchEnumerate ({12,3}):#effect on the tuple +     Print(i) -      the(0, 3) *(1, 12)

Python built-in function enumerate ()

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.