Javatpoint Logo
Javatpoint Logo

Python slice() Function

Python slice() function is used to get a slice of elements from the collection of elements. Python provides two overloaded slice functions. The first function takes a single argument while the second function takes three arguments and returns a slice object. This slice object can be used to get a subsection of the collection. For example, if we want to get first two elements from the ten element?s list, here slice can be used. The signature of this function is given below.



start: Starting index of slicing.

stop: End index of the slice

step: The number of steps to jump.


It returns a slice object.

Let's see some examples of slice() function to understand it's functionality.

Python slice() Function Example 1


slice(None, 5, None)
slice(0, 5, 3)

Python slice() Function Example 2



Python slice() Function Example 3


(45, 1214, 636)
(66, 41, 68)

Python slice() Function Example 4


(45, 1214, 636)
(45, 1214, 636)

Next TopicPython Set

Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials

B.Tech / MCA