li = [0, 1, 2, 3, 4, 5, 6, 7, 8]
print("li[-1:]: ", li[-1:])
print("li[:-1]: ", li[:-1])
print("li[0:2]: ", li[0:2])
输出
li[-1:]: [8]
li[:-1]: [0, 1, 2, 3, 4, 5, 6, 7]
li[0:2]: [0, 1]
li = [0, 1, 2, 3, 4, 5, 6, 7, 8]
print("li[-1:]: ", li[-1:])
print("li[:-1]: ", li[:-1])
print("li[0:2]: ", li[0:2])
输出
li[-1:]: [8]
li[:-1]: [0, 1, 2, 3, 4, 5, 6, 7]
li[0:2]: [0, 1]