1:
>>> range(10, 0, -1)
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(0, 10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(5, 10)
[5, 6, 7, 8, 9]
>>> range(5, 10, 2)
[5, 7, 9]
>>> range(10, 5, -2)
[10, 8, 6]
2:
def test_range(n):
for i in range(n):
print i print '****************************************'
for j in range(0, n):
print j print '****************************************'
for k in range(5, n):
print k print '****************************************'
for m in range(0, n , 2):
print m print '****************************************'
for n in range(n, 0, -1):
print n
输出:
0
1
2
3
4
5
6
7
8
9
****************************************
0
1
2
3
4
5
6
7
8
9
****************************************
5
6
7
8
9
****************************************
0
2
4
6
8
****************************************
10
9
8
7
6
5
4
3
2
1