14-元组

2018-10-26  本文已影响6人  努力爬行中的蜗牛
元组定义

元组(Tuple)和列表类似,不同之处在于元组不能修改。

tuple_list = ("zhangsan","lisi","wangwu")
info_tuple = ("zyx",18,1.75)
print(info_tuple[0])
print(info_tuple[1])
#元组只包含一个元素时,需要在后面跟上,
one_tupel = ("onlyone",)
print(type(one_tupel))
元组的常用操作
info_tuple. 
                     info_tuple.count   
                     info_tuple.index   
info_tuple = ("zyx",18,1.75)
print(info_tuple.index("zyx"))
print(info_tuple.count(18))
元组的循环遍历
for temp in info_tuple:
    print(temp)
元组的应用场景
print("姓名:%s,年龄:%d,身高:%.2f",info_tuple)
元组与列表之间的转换
info_list = list(info_tuple)
info_yuanzu = tuple(info_list)
上一篇 下一篇

猜你喜欢

热点阅读