Python slice() FunctionPython 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. SignatureParametersstart: Starting index of slicing. stop: End index of the slice step: The number of steps to jump. ReturnIt returns a slice object. Let's see some examples of slice() function to understand it's functionality. Python slice() Function Example 1Output: slice(None, 5, None) slice(0, 5, 3) Python slice() Function Example 2Output: Jaot toa Python slice() Function Example 3Output: (45, 1214, 636) (66, 41, 68) Python slice() Function Example 4Output: (45, 1214, 636) (45, 1214, 636)
Next TopicPython Set
|