Slice -list, string sections -list, string

Slice -list, string

 

1, the string, the end of the slice care regardless

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

2、list

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

3, step

= D [12,34,45,50,60]  : Print (D [:: 2]) results [12, 45, 60]  compartments takes a value of two

1, the string, the end of the slice care regardless

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

2、list

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

3, step

= D [12,34,45,50,60]  : Print (D [:: 2]) results [12, 45, 60]  compartments takes a value of two

Guess you like

Origin www.cnblogs.com/fandonghua/p/11586166.html