DAY4(PYTHON)列表的嵌套,range,for

时间:2021-06-21 18:11:08

li=['a','b','开心','c']

print(li[2].replace ( ' 心 ', ' kaixin ' ) )

输出:'a','b','开kaixin','c'

li= ['abctai','sfasf','safsa',['sfa','sed',89],23]

li [3][1]=li [3][1].upper()

print(li)

输出: li= ['abctai','sfasf','safsa',['STA','sed',89],23]

元祖:只读列表,可循环查询,可切片

tu=(1, 2, 3, 'demo', [2,2,4,'taibao'], 'abc')

print(tu[0:4])

demo

列表转化成字符串  list--->str   join

s='alex'

s1='_'.join(s)

print(s1)

输出:a_l_e_x(join接的是连接)

#range

for i in range(0,10):

  print ( i )

输出:0

#for i in range (0,10,3):

  print ( i )

输出:0