Python Language Reversing Elements


Example

Reverse elements within a tuple

colors = "red", "green", "blue"
rev = colors[::-1]
# rev: ("blue", "green", "red")
colors = rev
# colors: ("blue", "green", "red")

Or using reversed (reversed gives an iterable which is converted to a tuple):

rev = tuple(reversed(colors))
# rev: ("blue", "green", "red")
colors = rev
# colors: ("blue", "green", "red")