range() allows users to generate a series of numbers within a given range. Depending on how many arguments the user is passing to the function, the user can decide where that series of numbers will begin and end as well as how big the difference will be between one number and the next.range() takes mainly three arguments.
- start: integer starting from which the sequence of integers is to be returned
- stop: integer before which the sequence of integers is to be returned.
The range of integers end at stop – 1.
- step: integer value which determines the increment between each integer in the sequence
Note: For more information, refer to Python range() function
0 1 2 3 4 5 6 7 8 9
Slicing Range function
In Python, range objects are not iterators but are iterables. So slicing a range() function does not return an iterator but returns an iterable instead.
Now our new range ‘ans’ has numbers from 0 to 50 (50 exclusive). So a generalization for understanding this is
a[start : end : the difference between numbers]
So doing something like
ans = a[10:89:3] will have a range of numbers starting from 10 till 89 with a difference of 3 in between them.
range(10, 89, 3) range(0, 100, 5)
- Python | Alternate range slicing in list
- String Slicing in Python
- Python | K elements Slicing
- Python | Reverse Slicing of given string
- Python List Comprehension and Slicing
- Python | Custom List slicing Sum
- Python | Variable list slicing
- Python | Custom slicing in List
- Python - Convert 2D list to 3D at K slicing
- Interesting facts about strings in Python | Set 2 (Slicing)
- Python | Reverse Interval Slicing String
- Python Slicing | Extract ‘k’ bits from a given position
- Python | Get the substring from given string using list slicing
- Python | Reverse Incremental String Slicing
- Python Slicing | Reverse an array in groups of given size
- Basic Slicing and Advanced Indexing in NumPy Python
- Program to cyclically rotate an array by one in Python | List Slicing
- Python range() function
- String slicing in Python to check if a string can become empty by recursive deletion
- String slicing in Python to rotate a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.