Slicing range() function in Python Last Updated : 03 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 Example: Python3 # Python Program to # show range() basics # printing a number for i in range(10): print(i, end =" ") print() Output: 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. Example: Python3 # Python program to demonstrate # slicing of range function a = range(100) # Slicing range function ans = a[:50] print(ans) Output: range(0, 50) 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. Example: Python3 # Python program to demonstrate # slicing of range function a = range(100) # Slicing range function ans = a[10:89:3] print(ans) ans = a[::5] print(ans) Output: range(10, 89, 3) range(0, 100, 5) Comment More infoAdvertise with us Next Article Python slice() function D dhruvpanwar31 Follow Improve Article Tags : Python python-basics Practice Tags : python Similar Reads Python range() function The Python range() function returns a sequence of numbers, in a given range. The most common use of it is to iterate sequences on a sequence of numbers using Python loops.ExampleIn the given example, we are printing the number from 0 to 4.Pythonfor i in range(5): print(i, end=" ") print()Output:0 1 7 min read Python range() function The Python range() function returns a sequence of numbers, in a given range. The most common use of it is to iterate sequences on a sequence of numbers using Python loops.ExampleIn the given example, we are printing the number from 0 to 4.Pythonfor i in range(5): print(i, end=" ") print()Output:0 1 7 min read Python slice() function In this article, we will learn about the Python slice() function with the help of multiple examples. Example Python3 String = 'Hello World' slice_obj = slice(5,11) print(String[slice_obj]) Output: World A sequence of objects of any type (string, bytes, tuple, list, or range) or the object which im 5 min read Python slice() function In this article, we will learn about the Python slice() function with the help of multiple examples. Example Python3 String = 'Hello World' slice_obj = slice(5,11) print(String[slice_obj]) Output: World A sequence of objects of any type (string, bytes, tuple, list, or range) or the object which im 5 min read Python int() Function The Python int() function converts a given object to an integer or converts a decimal (floating-point) number to its integer part by truncating the fractional part.Example:In this example, we passed a string as an argument to the int() function and printed it.Pythonage = "21" print("age =", int(age) 3 min read Python | Custom slicing in List Sometimes, while working with Python, we can come to a problem in which we need to perform the list slicing. There can be many variants of list slicing. One can have custom slice interval and slicing elements. Let's discuss problem to such problem. Method : Using compress() + cycle() The combination 2 min read Like