Reversing Elements

suggest change

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 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")

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents