Range function => create a sequential list of numbers
# one argument call
numbers = list(range(10))
print(numbers)
[0,1,2,3,4,5,6,7,8,9]
The call to the list is necessary because range by itself creates a range object , and this must be converted to a list if you want to use it as one..
#two arguments call
numbers = list(range(3,8))
print(numbers)
[3,4,5,6,7]
print (range(20)==range(0,20))
True
#third arguments call
=>determines the interval of the sequence , third argument must be "int"
numbers = list(range(5,20,2))
print(numbers)
[5,7,9,11,13,15,17,19]
No comments:
Post a Comment