t=tuple(range(10)) #建立一个元组,长度为10 ,范围为 0-9 print(t) #(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) print(t[2]) #2 print(t[-1]) #显示倒数第一个数 print(t[::2]) #显示以0开始,步长为2的数
#split()函数将制定字符串切分为列表 #函数参数缺省时用空格切分,多个空格切分一次 #参数是空格时用一个空格切分,多个空格切分多次 s='life is short ,you need think highly of it ' lsa=s.split(',') lsb=s.split() lsc=s.split(' ') print(lsa) #['life is short ', 'you need think highly of it '] print(lsb) #['life', 'is', 'short', ',you', 'need', 'think', 'highly', 'of', 'it'] print(lsc) #['life', 'is', 'short', ',you', 'need', '', '', '', '', '', 'think', 'highly', 'of', 'it', '']