List Slicing Syntax


#1

Can you please explain what is a stride in this syntax.
[start:end:stride]


#2

@fra10 take a look at this code snippet

s = "codeacademy"

print s[::1]  #codeacademy
print s[::-1 ]#ymedacaedoc

print s[::2] #cdaaey
print s[::-2] #yeaadc

in list slicing what the stride does is it specifies what the step should be. if the value of the stride 1 then it means moved through the given string with only one step at a time(i.e move to to the next element right from the previous) but if the value of stride is 2 then it means move through the list but this time jump two characters each time.

if the stride is negative then the slicing goes in the reverse(i.e. start slicing from the end)

CHeck out this snippet on labs


#3

Thank you for the effort.
Hope you have a nice day.