info_tuple = ("Tom", 18, 1.85)
print(type(info_tuple))
print(info_tuple)
print(info_tuple[0])
info_tuple_01 = ()
print(type(info_tuple_01))
- 定义一个只有一个元素的元组
info_tuple_02 = (5) # 错误示例
print(type(info_tuple_02)) # 输出<class ‘int’>
info_tuple_03 = (5,)
print(type(info_tuple_03))
- 元组的常用操作
- 使用.count()方法统计同一个元素在元组中出现的次数
info_tuple= ("Tom", 18, 1.78, 120, 120)
print(info_tuple.count(120))
- 使用.index()方法查看指定元素的索引值,多个相同元素会输出第一次位置的索引值
info_tuple= ("Tom", 18, 1.78, 120, 120)
print(info_tuple.index(120))
info_tuple= ("Tom", 18, 1.78, 120, 120)
print(len(info_tuple))