创建元组
#元组
'''
特点:
1.Python内置的数据结构之一,存在于字典中,是不可变序列
2.没有增删改操作
'''
'''
可变序列:列表 字典(增删改操作,不改变id)
不可变序列:字符串,元组(增删改操作,改变id,即存储位置,意味着生成了新的序列)
'''
#元组与列表类似,元组用(),列表用[]
#创建元组的方法
#1.使用(),或者不使用,直接赋值
t=('hello','world',1,2,3,5,6,8)
g='hello','world',1,2,3,5,6,8
print(g)
print(type(t))
#2.使用内置函数tuple()
h=tuple(('hello','world',1,2,3,5,6,8))
print(h)
#只包含一个元素的元组需要使用逗号和小括号,负责会认为是string类型
f=(10,)
print(type(f))
元组的遍历
t=('hello','world',1,2,3,5,6,8)
#元组的遍历,1.通过索引 2.通过for
for item in t:
print(item)