Python in enumerate, xrange, range

Source: Internet
Author: User

Enumerate
You can automatically generate a column for the list, starting from 0, and automatically growing by 1, you can specify a default start value

List_product = ["ThinkPad", "MacBook", "Iphone8", "Robbit"]for key,v in Enumerate (list_product,1):    print (KEY,V)

Range 2.7 To get the number in the specified range
1. Range (0,1000000), all data is created in memory at once
2, Xrange,xrange (0,100000), only in the loop output, only one time to create data
Python 3 has only a range equal to the function of the xrange in 2.7, with a range of 0 to 10, and a default step of 1

For T in range (1,10):    print (t)

All even numbers of output 1-10

For Oushu in range (0,11,2):  print (Oushu)

Output 1-10 all odd numbers

For Jishu in range (1,11,2):  print (Jishu)

Output 10,9,8,7....0

For I in Range (10,0,-1):    print (i)

Python in enumerate, xrange, range

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.