用python实现:按相反的顺序输出列表的每一位值
1. 使用list[::-1]
1 list1 = ["one","two","three","four"] 2 for i in list1[::-1]:#list[::-1]结果为列表的反向 3 print(i)
2. 使用list方法reverse()
1 list1 = ["one","two","three","four"] 2 list1.reverse() 3 for i in list1: 4 print(i)
3. 使用python内置函数
1 list1 = ["one","two","three","four"] 2 list2 =reversed(list1) 3 for i in list2: 4 print(i)
执行结果:
four three two one