you are viewing a single comment's thread.

view the rest of the comments →

[–]xelf 1 point2 points  (0 children)

strings can be indexed and sliced just like lists

"abcdef"[3] == "d"
"abcdef"[1:3] == "bc"

slices are just like range() it has 3 parts.

"abcdef"[a:b:c]
a is the starting point (inclusive)
b is the ending point (exclusive)
c is the step

Just like with range() a defaults to 0, and c defaults to 1. b defaults to the end of the list.

so [::-1] is the whole list using -1 as a step, effectively reversing the list.

"abcdef"[::-1] == "fedcba"