在python的資料列中,取得倒數某個資料,可能會利用索引負值,以list為例如下
a = [1, 2, 3, 4, 5]
print(a[-1])
#5
a = [1, 2, 3, 4, 5]
print(a[::-1])
#[5, 4, 3, 2, 1]
a = [1, 2, 3, 4, 5] print(a[-3:])
#[3, 4, 5]
x='ChatGDP and BingAI'
print(x[-6:-3]) =>Bin
print(x[-6:3]) => not output
print(x[6:-3])=>P and Bin
print(x[6:3])=> not output
要特別留意