1. 程式人生 > 其它 >Python 作業:列表切片的應用

Python 作業:列表切片的應用

技術標籤:2020網路班PythonPython

作業要求:使用者輸入一個列表和兩個整數作為下標,然後使用切片獲取並輸出列表中介於兩個下標之間的元素組成的子列表。例如,使用者輸入[1,2,3,4,5,6]和2、5,程式輸出[3,4,5,6]

參考程式碼:

sList=input("請輸入一個列表:")
intList=eval(sList)
print(intList)
sIndex=input("請輸入二個下標整數:")
iIndexA,iIndexB=tuple(map(int,sIndex.split("、")))
print(intList[iIndexA:iIndexB])