0X01 Function Description:
python range () function creates a list of integers, generally used in a for loop.
0X02 function syntax:
range(start,stop[,step])
- start: start counting from the beginning. The default is zero. E.g. range (5) is equivalent to the range (0, 5);
- stop: stop counting to the end, but not stop. For example: range (0, 5) is [0, 1, 2, 3, 4] No 5
- step: the step size, the default is 1. For example: range (0, 5) is equivalent to the range (0, 5, 1)
For example:
1 # set sequence of integers from 0 to 10 2 Range1 = Range (10 ) . 3 for Range1 in Range1: . 4 Print ( " list range (10) elements of the output: " , Range1) . 5 . 6 Print ( " ---- ----------------------------------------- " ) . 7 . 8 # set step size 5 is a sequence of 0 to 30 . 9 Range2 = Range (0,30,5 ) 10 for Range2 in Range2: . 11 Print ( " list range (0,30,5) elements of the output: " , Range2) 12 13 Print ( " --------------------------------------------- " ) 14 15 # Range for recycling with 16 new_str = " the I AM a Genius " . 17 for a in Range (len (new_str)): 18 is Print ( " among the letter strings: " , new_str [a])
operation result:
. 1 /Users/aaron/.PyCharmCE2019.3/config/scratches/: C: \ the Users \ Aaron \ Desktop \ Pytoon-Cade \ Venv \ the Scripts \ python.exe C scratch.py 2 (10 listing Range ) output element: 0 3 (10) elements of the output list Range:. 1 . 4 (10) elements of the output list Range: 2 . 5 (10) elements of the output list Range: 3 . 6 (10) elements of the output list Range:. 4 . 7 (10) elements of the output list range: 5 8 list range (10) elements of the output: 6 . 9 (10) a list of elements of the output Range:. 7 10 (10) elements of the output list Range: 8 . 11 listing range (10) elements of the output: 9 12 is --------- ------------------------------------ 13 list Range (0,30,5 ) output elements: 0 14 list range (0,30,5) output elements: 5 15 list range (0,30,5) output elements: 10 16 listing range (0,30,5) output elements: 15 . 17 listing range (0,30,5) output elements: 20 18 is listing range (0,30, 5) elemental output: 25 . 19 ------------------------------------------- - 20 is the letter string from among: the I 21 is among a string of letters: 22 among the letter string: a 23 is among a string of letters: m 24 among a string of letters: 25 strings among the letters: a 26 is character letter string from among: 27 strings among the letters: G 28 among a string of letters: E 29 from among the letter strings: n- 30 among a string of letters: I 31 is the string of letters among: U 32 strings among letters: S 33 is 34 is Process finished with exit code 0