切片/函数
L = ['a','b','c','d','e','f']
print(L[0:3])
print(L[:2])
print(L[-2:-1])
print(L[-2:])
print(L[1:])
print(L[::2])
print(L[::3])
print(L[0:0])
print(L[2:-1])
print(L[:])
x = input('x :')
y = input('y :')
x = int(x)
y = int(y)
def main(x,y):
if x<y:
print(L[x:y])
else:
print(L[y:x])
main(x,y)
展示
['a', 'b', 'c']
['a', 'b']
['e']
['e', 'f']
['b', 'c', 'd', 'e', 'f']
['a', 'c', 'e']
['a', 'd']
[]
['c', 'd', 'e']
['a', 'b', 'c', 'd', 'e', 'f']
x :5
y :2
['c', 'd', 'e']