# Parsing Python range function usage

Source: Internet
Author: User

Python Range Function Usage

One, in the Python development application, the range function is very important, but also more commonly used :

first look at the prototype of the range function: range (start, end, scan)

parameter resolution:

Start: Count starts from start. The default is starting from 0. For example, range (5) is equivalent to range (0, 5);

End: The technology ends with end, but does not include end. For example: Range (0, 5) is [0, 1, 2, 3, 4] No 5 (commonly known: after the package is not wrapped)

Scan: The distance between each hop is 1 by default. Example: Range (0, 5) is equivalent to range (0, 5, 1)

Second, according to the specific code, see a range of functions in the specific use of Python3.7:

Since the range (0,5) in Python 3.7 does not directly output the sequence [0, 1, 2, 3, 4], this is where Pycharm uses the For loop to show the app

`1  forIinchRange (5):2     Print(i,end=' ')#Output [0, 1, 2, 3, 4]3 4  forIinchRange (0,5):5     Print(i,end=' ')#Output [0, 1, 2, 3, 4]6 7  forIinchRange (-5):8     Print(i,end=' ')#Output []9 Ten  forIinchRange (0, 5, 2): One     Print(I, end=' ')#Output [0, 2, 4] A  -  forIinchRange (0,-5, 2): -     Print(I, end=' ')#Output [0, -2, -4]`
Range function Case

This also makes a bubble sort based on the range function.

`1Array = [1, 2, 5, 3, 6, 8, 4]2  forIinchRange (len (array)-1, 0, 1):3     Print(Array[i], end=' ')4 5  forIinchRange (0, Len (array), 1):6     Print(i)7      forJinchRange (i + 1, len (array), 1):8         ifARRAY[J] <Array[i]:9ARRAY[J], array[i] =Array[i], Array[j]Ten  One Print(array)`
python bubble sort

Parsing Python range function usage

Related Keywords:
Related Article

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.