切片-list、字符串 切片-list、字符串

切片-list、字符串

 

1、字符串,切片顾头不顾尾

s="123455" print(s[0:3])  结果:123

2、list

d=[12,34,45]  print(d[:2]) 结果:[12, 34] 

3、步长

d=[12,34,45,50,60]  print(d[::2]) 结果:[12, 45, 60] 隔两个取一个值

1、字符串,切片顾头不顾尾

s="123455" print(s[0:3])  结果:123

2、list

d=[12,34,45]  print(d[:2]) 结果:[12, 34] 

3、步长

d=[12,34,45,50,60]  print(d[::2]) 结果:[12, 45, 60] 隔两个取一个值

猜你喜欢

转载自www.cnblogs.com/fandonghua/p/11586166.html