Chapter 6 Built-in Functions
6.1 range
range(X) generates sequence of integer object
range (lower_bound, upper_bound, step_size)
# lower bound is optional, default = 0
# upper bound is not included in result
# step is optional, default = 1
Use list() to convert in order to view actual sequence of data
= range(10) # default lower bound =0, step =1
r print (type (r))
## <class 'range'>
print (r)
## range(0, 10)
print (list(r))
## [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
More Examples
print (list(range(2,8))) # step not specified, default 1
## [2, 3, 4, 5, 6, 7]
print ('Odds Number : ' , list(range(1,10,2))) # generate odds number
## Odds Number : [1, 3, 5, 7, 9]