1.元组的概述:
元组与列表类似,由任意类型的元素组成序列;
元组是不可变的(与列表不同处);
2.元组的创建及检验:
>>> tuple_1 = (1,2,3,4) >>> tuple_1 (1, 2, 3, 4) >>> tuple_2 = 1,2,3 >>> tuple_2 (1, 2, 3) >>> tuple_3 = (1) >>> type(tuple_3) <class 'int'> >>> tuple_3 = (1,) #注意,创建单个值的元组时候,必须后面加, >>> type(tuple_3) <class 'tuple'> >>> tuple_3 = 1, >>> type(tuple_3) <class 'tuple'> >>> tuple_3 (1,)
>>> tuple_4=() #创建空元组直接括号即可。
>>> type(tuple_3)
<class 'tuple'>
标签:tuple,Python,创建,元组,数据结构,type From: https://www.cnblogs.com/chig/p/16942414.html