#元祖tupe #元祖被称为只读列表,即数据可以被查询,但不能被修改,所以,字符串的切片操作同样适用于元祖。例:(1,2,3) ("a","b","c") tu = (1,2,3,'dexter',[2,3,4,'dapeng'],'tom') print (tu[3]) #dexter print (tu[0:4]) #(1, 2, 3, 'dexter') for i in tu: print(i) ''' 1 2 3 dexter [2, 3, 4, 'dapeng'] tom ''' #儿子不能改,孙子可能可以改 tu[4][3] = tu[4][3].upper() print(tu) #(1, 2, 3, 'dexter', [2, 3, 4, 'DAPENG'], 'tom') #修改元祖报错 #tu[3] = tu[3].capitalize() #print(tu) tu[4].append('sd') print(tu) #(1, 2, 3, 'dexter', [2, 3, 4, 'DAPENG', 'sd'], 'tom') s = 'dexter' s1 = '_'.join(s) print(s1) #d_e_x_t_e_r #列表转换为字符串 li = ['10.88.140.69', '10.88.139.23', '10.88.67.42'] l1 = ','.join(li) print(l1) #10.88.140.69,10.88.139.23,10.88.67.42 #字符串转换为列表 str = '10.88.140.69,10.88.139.23,10.88.67.42' print(str.split(',')) #['10.88.140.69', '10.88.139.23', '10.88.67.42'] for i in str.split(','): print(i) ''' 10.88.140.69 10.88.139.23 10.88.67.42 ''' #元祖转换为字符串 li = ('10.88.140.69', '10.88.139.23', '10.88.67.42') l1 = '+'.join(li) print(l1) #10.88.140.69+10.88.139.23+10.88.67.42