元祖里是数据是固定的,不能修改
1 str_tuple = ('dew','','as') 2 3 int_tuple = (1,2,4,5,4) 4 5 float_tuple = (1.1,20.3,23.9) 6 7 bool_tuple = (True,False,False,True) 8 9 none_tuple = (None,None,None) 10 11 tuple_tuple = ((1,2,3),(1.2,3.1)) 12 13 list_tuple = ([123,456],[2345,1234]) 14 15 mix_tuple = ('de',1,3.14,None,True)
列表与元祖的区别
1.元祖比列表占用资源更小
2.列表是可变的,元祖是不可变的
max和min在元祖中使用的时候,元祖中的元素不能是多种类型,如果类型不统一,则会报错
如果只有一个元祖元素,后面必须要加","
# coding:utf-8 tuple_test = ('de',) print(tuple_test) print(type(tuple_test))
如果没有元素
tuple_01 = () //创建方式一 常用
tuple_01 = tuple() //创建方式二 print(type(tuple_01)) //<class 'tuple'>
标签:None,01,tuple,python,print,test,元祖 From: https://www.cnblogs.com/qjb2404/p/16886297.html