Range () and xrange () methods

Source: Internet
Author: User

Range () method

The Range method, which creates a new list that contains a series of integers. The general form of calling the Range method is to provide a single value as the upper bound of the integer list. Zero is the starting value.

>>>range (8) [0,1,2,3,4,5,6,7]>>>range (2,8) [2,3,4,5,6,7]>>>range (2,15,2) [ 2,4,6,8,10,12,14]

x Range () method

The Xrange method also creates an integer list (which uses the same parameters), so it is very similar to the Range method. However, the Xrange method creates an integer in the list only when it is needed. For example, in Listing 6, when you try to print out the newly created xrange, no data is displayed except for the xrange name. The Xrange method is more appropriate when you need to iterate over a large number of integers because it does not create a large list, which consumes a lot of computer memory.

Range () and xrange () methods

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.