xxxxxxxxxx
>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(1, 11))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> list(range(0, 30, 5))
[0, 5, 10, 15, 20, 25]
>>> list(range(0, 10, 3))
[0, 3, 6, 9]
>>> list(range(0, -10, -1))
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
>>> list(range(0))
[]
>>> list(range(1, 0))
[]
xxxxxxxxxx
range(4) # [0, 1, 2, 3] 0 through 4, excluding 4
range(1, 4) # [1, 2, 3] 1 through 4, excluding 4
range(1, 10, 2) # [1, 3, 5, 7, 9] 1 through 10, counting by 2s
xxxxxxxxxx
# subcribe to my channel
# https://www.youtube.com/channel/UCakNP54ab_3Qm8MPdlG4Zag
def own_range(start=0, end=0, step=1):
if step == 0:
raise ValueError("own_range() arg 3 must be not zero")
if start > end and step < 0:
while start > end:
yield start
start += step
elif start > end or (start != 0 or end == 0) and start != 0 and end == 0:
while end < start:
yield end
end += step
elif start == 0 and end != 0 and end > 0 and step > 0 or (start != 0 or end == 0) and start != 0 and start < end and step > 0:
while start < end:
yield start
start += step
xxxxxxxxxx
# plz suscribe to my youtube channel -->
# https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A
def range_by(starting_number, ending_number):
#sequence = [starting_number]
sequence = []
while starting_number < ending_number:
sequence.append(starting_number)
starting_number += 1
return sequence
print(range_by(-3,6))
xxxxxxxxxx
range(start:optional, stop:required, step:optional)
A built-in python function to create a sequence of integers.
range(10) #[0 to 9]
range[2,9] #start 2 and stop 10
print(list(range(10))) #change create range object into list.
range(1,100,10)
xxxxxxxxxx
# if numbers are same in the range function then,
# the range function outputs empty range
# this is because, there are no integers b/w n and n
for i in range(1,1):
print("runs")
# prints nothing