Python tutorial #7 :Range


SUBMITTED BY: Guest

DATE: Dec. 16, 2013, 8:40 a.m.

FORMAT: Python

SIZE: 511 Bytes

HITS: 919

  1. # range
  2. # 2.x : list
  3. # 3.x : object of type range
  4. # iterable:
  5. # gives values one after another
  6. # at some points, says thats the end
  7. # - keep all values ready; give one when asked for
  8. # - make them when asked for
  9. print (range(5))
  10. print (list(range(5))) # 0 to 5; 5 not inclusive
  11. print (list(range(5, 10))) # 5 6 7 8 9
  12. print (list(range(5, 20, 3))) # 5 8 11 14 17
  13. # range(final) # init = 0, step = 1
  14. # range(init, final)
  15. # range(init, final, step)

comments powered by Disqus