切片

l = list(range(100))

print(l)
[0,1,2,3,4,5...99]

print[0:10]
[0,1,2,3,4,5,6,7,8,9]

print[-10:]
[90,91,92,93,94,95,96,97,98,99]

print[10:20]
[10,11,12,13,14,15,16,17,18,19]

print[:10:2]
[0,2,4,6,8]

print[::5]
[0,5,10,....95]

(1,2,3,4,5,6)[:5]
[1,2,3,4,5]

'abcdefg'[1:5]
[bcdef]

你可能感兴趣的:(切片)