Reversing Elements
suggest changeReverse 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 returns an iterator, which is converted to a tuple). This starts again from the original tuple; the block above has already rebound colors:
colors = "red", "green", "blue"
rev = tuple(reversed(colors))
# rev: ("blue", "green", "red")
colors = rev
# colors: ("blue", "green", "red")
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents