Answers for "python create range"

11

making your own range function in python

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))
Posted by: Guest on June-30-2021
16

making your own range function with step in python

def range_with_step(start_num,end_num,step_num):
    sequence2 = [start_num]
    while start_num < end_num:
        start_num += step_num
        sequence2.append(start_num)
    return sequence2
print(range_with_step(0,6,3))
Posted by: Guest on June-30-2021
1

range(n,n) python

# 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
Posted by: Guest on June-10-2020
0

range python start at 1

>>> def range1(start, end):
...     return range(start, end+1)
...
>>> range1(1, 10)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Posted by: Guest on April-07-2020

Python Answers by Framework

Browse Popular Code Answers by Language