number_tuple=(1,3,5,7,9)
string_tuple =("abc","bbc","python")
mixed_tuple=("python","java",3,12)
print("string_tuple"+str(string_tuple))
print("mixed_tuple"+str(mixed_tuple))
second_num=number_tuple[1]
third_string=string_tuple[2]
fourth_mixed=mixed_tuple[3]
print("second_num:{0}\n third_string:{1}\nfourth_mixed:{2}".format(second_num,third_string,fourth_mixed))
#===============================================================================
# tuple不可以更新,故以下报错
# number_tuple[1]=30
# print("number_list_after:"+str(number_tuple))
#
# 删除tuple内容,同样是报错的
# del number_tuple[1]
# print("number_tuple_after:"+str(number_tuple))
#===============================================================================
#del mixed_tuple
#print(mixed_tuple)
#但是可以删除整个tuple
print(len((1,2,3)))
print((1,2,3)+(4,5,6))
print('hello'*4)
print(3 in (1,2,3))
abcd_tuple=('a','b','c','d')
print(abcd_tuple[1])
print(abcd_tuple[-2])
print(abcd_tuple[1:])
=======
tuple其他用法,按顺序给每一个元素赋值,如下:
v=('a','b','c')
(x,y,z)=v