{"id":25584,"date":"2021-11-23T08:55:02","date_gmt":"2021-11-23T03:25:02","guid":{"rendered":"https:\/\/python-programs.com\/?p=25584"},"modified":"2021-11-23T08:55:02","modified_gmt":"2021-11-23T03:25:02","slug":"python-itertools-islice-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-itertools-islice-function-with-examples\/","title":{"rendered":"Python Itertools.islice() Function with Examples"},"content":{"rendered":"

Itertools Module:<\/strong><\/p>\n

Itertools is a Python module that contains a collection of functions for dealing with iterators. They make it very simple to iterate through iterables such as lists and strings.<\/p>\n

Itertools.islice() Function:<\/strong><\/p>\n

This iterator prints only the values specified in the iterable container passed as an argument.<\/p>\n

Syntax:<\/strong><\/p>\n

islice(iterable, start, stop, step)<\/pre>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [10, 20, 30, 40]\r\nGiven start = 2\r\nGiven stop =  25\r\nGiven step = 3<\/pre>\n

Output:<\/strong><\/p>\n

[30]<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [2, 5, 6, 7, 8]\r\nGiven start = 3\r\nGiven stop = 20\r\nGiven step = 3<\/pre>\n

Output:<\/strong><\/p>\n

[7]<\/pre>\n

Itertools.islice() Function with Examples in Python<\/h2>\n