Python反转元素
示例
元组中的反向元素
colors = "red", "green", "blue" rev = colors[::-1] # rev: ("blue", "green", "red") colors = rev # colors: ("blue", "green", "red")
或使用反向(反向给出可迭代的值,该值将转换为元组):
rev = tuple(reversed(colors)) # rev: ("blue", "green", "red") colors = rev # colors: ("blue", "green", "red")