Python's range () function, for-in loop, and while loop

Source: Internet
Author: User

Range () function and for-in loop

function Prototypes : Range (start, end, scan):

parameter meaning : 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

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

code example:

1  forNinchRange (3):2     Print(n)3     4 Print("-----------------------")5 6  forNinchRange (2, 4):7     Print(n)8     9 Print("-----------------------")Ten  One  forNinchRange (2, 8, 2): A     Print(n)

Output:

0
1
2
-----------------------
2
3
-----------------------
2
4
6

While loop :

1 m = 02 while M < 3:3     print (m) 4     M + = 1

Results:

0
1
2

Python's range () function, for-in loop, and while loop

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.