以下代码正常工作,正如预期的那样(在数组中打印元素):
arr = []
n = int(raw_input())
for i in range (0,n):
num = int(raw_input())
arr.append(num)
for i in range(0,n):
print arr[i]
但是,当我尝试以相反的顺序打印数组元素时,
arr = []
n = int(raw_input())
for i in range (0,n):
num = int(raw_input())
arr.append(num)
for i in range(0,n):
print arr[n-i] #notice this line
这给了我:IndexError: list index out of range
。