元组的使用方法
元组 :tuple
跟列表几乎一模一样,元组是无法修改的,元组使用()
c = ('hello','python','linux','mysql','git') print(type(c)) print(c[1]) print(len(c))
当你的元组中,只有一个元素的时候,在最后面加上一个,(英文的逗号)
d = ('hello',) print(type(d))
元组 是一个不可变的列表
a = ('python','java','php','php','php')
统计元素出现的次数 count()
res = a.count('php') print(res)
统计元素的下标 index()
res = a.index('php') print(res)