- range()
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(5,10)
[5, 6, 7, 8, 9]
>>> list(range(0,10,3))
[0, 3, 6, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(5,10)
[5, 6, 7, 8, 9]
>>> list(range(0,10,3))
[0, 3, 6, 9]
>>> list(range(10,0,-3))
[10, 7, 4, 1]
range(stop) 0 ≦ i < stop
range(start, stop) start ≦ i < stop
range(start, stop, step) start ≦ i < stop
range(stop, start, -step) stop ≧ i > start
- for()
>>> names = ['pico', 'ted', 'hop']
>>> for i in names:
... print i
pico
ted
hop
- remove(), del()
>>> names = ['pico', 'ted', 'hop']
>>> names.remove('pico')
>>> names
['ted', 'hop']
>>> names.pop(1)
'hop'
>>> names
['ted']
- random(), uniform(), randrange(), randint()
>>> num = range(5)
>>> num
[0, 1, 2, 3, 4]
>>> random.randint(0, len(nums)-1)
4
No comments:
Post a Comment