按相反的顺序输出列表的值
法一:
a = ['one', 'two', 'three']
for i in a[::-1]:
print(i)
法二:
a = ['one', 'two', 'three']
print(a[-1::-1])
法三:使用reverse()
list = ['a', 'b', 'c', 'd']
list.reverse()
print( list)
法四:使用递归实现
a = ['one', 'two', 'three', 'four', 'five', 'six']
def reverse(a):
if len(a) <= 1:
print(a[0], end=" ")
else:
print(a[-1], end=" ")
reverse(a[0:-1])
reverse(a)
法五:
numbers=list(range(1,10))
list=[]
for i in range(1,10):
list.append(numbers.pop())
print(list)