Python Tuple - Slicing Using Step Parameter

The slicing operation on a python tuple with a step option, creates a slice by skipping elements at intervals specified the Step Value.
 

Parameters:

BeginIndex - Starting index of the tuple object
EndIndex   - EndIndex+1 of the tuple object
Step Value - Interval on which indexes and the elements at these indexes need to skipped

Return Value:

A tuple as specified in the slice method paramters. The tuple created is a result of shallow copying from the original tuple.

Example:

>>> FruitBasket = ('Apple', 'Orange', 'Banana', 'Grape', 'Raspberry')

>>> MyFruitPlate=FruitBasket[0:5:1]

>>> print(MyFruitPlate)

('Apple', 'Orange', 'Banana', 'Grape', 'Raspberry')

>>> MyFruitPlate=FruitBasket[0:5:2]

>>> print(MyFruitPlate)

('Apple', 'Banana', 'Raspberry')

>>> MyFruitPlate=FruitBasket[0:5:3]

>>> print(MyFruitPlate)

('Apple', 'Grape')

>>> MyFruitPlate=FruitBasket[0:5:4]

>>> print(MyFruitPlate)

('Apple', 'Raspberry')

>>> MyFruitPlate=FruitBasket[0:5:5]

>>> print(MyFruitPlate)

('Apple',)

>>> MyFruitPlate=FruitBasket[0:5:6]

>>> print(MyFruitPlate)

('Apple',)

>>> MyFruitPlate=FruitBasket[0:5:7]

>>> print(MyFruitPlate)

('Apple',)


Copyright 2023 © pythontic.com