目录
1、元祖的创建
Python 的元组与列表类似,不同之处在于元组的元素不能修改。
元组使用小括号 ( ),列表使用方括号 [ ]。
元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可。
tuple=('元素1', ‘元素2’, '元素3')。
>>> tup1 = ('Google', 'Runoob', 1997, 2000)
>>> tup2 = (1, 2, 3, 4, 5 )
>>> tup3 = "a", "b", "c", "d" # 不需要括号也可以
>>> type(tup3)
<class 'tuple'>
2、元祖的比较
operator模块支持丰富的对象比较操作,采用operator模块进行tuple元祖是否相等比较。
import operator
tuple1=('你好','北京')
tuple2=('你好','北京')
print(operator.eq(tuple2,tuple1))
#返回布尔值Ture or False