python元组tuple 发表于 2019-10-22 | 更新于 2023-01-11 python元组tuple练习12345678910111213141516171819202122232425262728293031# tuple不可修改列表my_tuple = ()print(my_tuple, type(my_tuple))my_tuple = tuple(range(10))print(my_tuple)# 可以省略括号my_tuple = 1, 2, 3, 4print(my_tuple)# 只有一个逗号的时候,必须有一个逗号my_tuple = (1,)print(my_tuple)my_tuple = 1,print(my_tuple)# 元组解构my_tuple = 'a', 'b', 'c'(a, b, c) = my_tupleprint(a, b, c)# 解构必须一致my_tuple = (1, 2, 3, 4, 5, 6)(a, b, *c) = my_tupleprint(a, b, c)# 交换变量a = 1b = 2(a, b) = (b, a)print(a, b)