Python – Itertools.islice()
In Python, Itertools is the inbuilt module that allows us to handle the iterators in an efficient way. They make iterating through the iterables like lists and strings very easily. One such itertools function is islice().
Note: For more information, refer to Python Itertools
This iterator selectively prints the values mentioned in its iterable container passed as an argument.
islice(iterable, start, stop, step)
0 1 2 3 4 [4, 7, 10]
1 2 3 4
Here we have provide the three-parameter that is
range(), 1 and 5. So the first parameter that is iterable as range and second parameter 1 will be considered as start value and 5 will be considered as stop value.
Here we provide the four-parameter that is
range() as iterable, 1, 5 and 2 as stop value. So the first parameter that is iterable as range and second parameter 1 will be considered as start value and 5 will be considered as stop value and 2 will be considered as step value of how many steps to skip while iterating values.