Python 1-13 元组

Python3 元组

https://www.runoob.com/python/python-tuples.html

元组创建,只需要在小括号中添加元素,并使用逗号隔开即可。

>>> tup1 = (1, 2, 3, 4, 5 )
>>> tup2 = "a", "b", "c", "d" # 不需要括号也可以
>>> type(tup2) <class 'tuple'>

创建空元组

tup1 = ()

元组中只包含一个元素时,需要在元素后面添加逗号,否则括号会被当作运算符使用:

>>>tup1 = (50)
>>&

猜你喜欢

转载自blog.csdn.net/weixin_43955170/article/details/112717602