Extended Slice and Getting Items From Sequence
· Def:-
Through slicing we can smartly extract items from sequences
by availing the third parameter of the slicing argument.
· Tip:-
Using the step(third) argument of the slicing we can
get the desired sub-sequence.
· Code:-
nameSeq = range(6)
· Sub-sequence of even indices:- nameSeq[::2]
#Result [0, 2, 4]
· Reverse Sub-sequence :- nameSeq[::-1]
#Result [5, 4, 3, 2, 1, 0]
HTML Comment Box is loading comments...