Python 3 Range usage

Source: Internet
Author: User

The Pytho range () function creates a list of integers, which is typically used in a for loop.

function syntax
Range(start, stop[, step])      

Parameter description:

  • Start: Count starts from start. The default is starting from 0. For example, range (5) is equivalent to range (0, 5);
  • End: Count to end, but do not include end. For example: Range (0, 5) is [0, 1, 2, 3, 4] No 5
  • Step: Step, Default is 1. Example: Range (0, 5) is equivalent to range (0, 5, 1)
    Range (10)#starting from 0 to ten[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]range (1, 11)#starting from 1 to one[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]range (0,30, 5)#Step size is 5[0, 5, 10, 15, 20, 25]range (0,10, 3)#Step size is 3[0, 3, 6, 9]range (0,-10,-1)#Negative number[0,-1,-2,-3,-4,-5,-6,-7,-8,-9]>>> Type (range (10))<class 'Range'>
    # print (range) # for I in range: #     print (i) # for I in Range (1,10,2): #     print (i) # # print (type (range)) str = ' He Llo! ' For I in range (len (str)):    print (str[i]) for I in Range (1,13):    # Print (' {} month '. Format (i)) # Format Usage    print ('%d month '% i)

      

Python 3 Range usage

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.