python list截取倒序,[]裏第一個 : 左右爲數組截取第索引位置(左邊爲大的索引位置,右邊爲小的索引位置,反過來),左邊如果爲空,默認爲最後一個索引位置,右邊爲空,默認爲索引0;後面 :-1 固定
a = [1, 3, 4, 2, 'a', 'd']
print a[3:1:-1]
print a[::-1]
print a[3::-1]
print a[:4:-1]
print a[3:1] #wrong format
output:
[2, 4]
[2, 4]
['d', 'a', 2, 4, 3, 1]
[2, 4, 3, 1]
['d']
[]