Python数据结构-序列

shopList=['apple','orange','pen']
print(shopList)
print('First thing is: '+shopList[0])
print('The last2 thing is: '+shopList[-2])

print('the 1 to 2 thing is: '+str(shopList[1:2]))
print('the 0 to 2 thing is: '+str(shopList[:2]))

运行结果:

['apple', 'orange', 'pen']
First thing is: apple
The last2 thing is: orange
the 1 to 2 thing is: ['orange']
the 0 to 2 thing is: ['apple', 'orange']

 

你可能感兴趣的:(python)