python的range()函数用法
参考http://www.cnblogs.com/buro79xxd/archive/2011/05/23/2054493.html
1 # -*- coding: utf-8 -*- 2 """ 3 Created on Thu Jun 22 16:20:19 2017 4 5 @author: PETER 6 """ 7 8 array = [1, 2, 5, 3, 6, 8, 4] 9 10 print(array[0:]) 11 print(array[1:]) 12 print(array[:-1]) 13 print(array[3:-3]) 14 15 print(array[::2]) 16 print(array[2::]) 17 print(array[::3]) 18 print(array[::4]) 19 20 #reverse数组 21 print(array[::-1]) 22 print(array[::-2]) 23 24 for i in range(len(array)-1,0,-2): 25 print(i) 26 print("\n") 27 for i in range(len(array)-1,0,-1): 28 print(i) 29 30 #[1, 2, 5, 3, 6, 8, 4] 31 #[2, 5, 3, 6, 8, 4] 32 #[1, 2, 5, 3, 6, 8] 33 #[3] 34 #[1, 5, 6, 4] 35 #[5, 3, 6, 8, 4] 36 #[1, 3, 4] 37 #[1, 6] 38 #[4, 8, 6, 3, 5, 2, 1] 39 #[4, 6, 5, 1] 40 #6 41 #4 42 #2 43 # 44 # 45 #6 46 #5 47 #4 48 #3 49 #2 50 #1 51