Python Language Éléments d'inversion


Exemple

Inverser les éléments dans un tuple

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

Ou en utilisant inversé (inversé donne un itérable qui est converti en un tuple):

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