1. reversed()python
a = [1, 2, 3, 4] for i in reversed(a): print(i)
2. range(len(a)-1, -1, -1)學習
a = [1, 2, 3, 4] for i in range(len(a)-1, -1, -1): print(a[i])
3. range(len(a)) + ~操做符
~按位取反運算符:對數據的每一個二進制位取反,即把1變爲0,把0變爲1 。~x 相似於 -x-1code
a = [1, 2, 3, 4] for i in range(len(a)): print(a[~i])
PS:遇到問題沒人解答?須要Python學習資料?能夠加點擊下方連接自行獲取
note.youdao.com/noteshare?id=2dce86d0c2588ae7c0a88bee34324d76學習資料
4. sliceclass
a = [1, 2, 3, 4] for i in a[::-1]: print(i)
5. length-i-1sed
a = [1, 2, 3, 4] seq_length = len(a) for i in range(seq_length):