Generating a range of numbers For practice I wrote a function to generate a list of numbers from a start to an end by a step. I couldn't make it- like the built-in range- default start to 0, because all optional parameters must come after required ones, so def range(start=0, end, step=1) won't work.

Here's my script:

def Range(start, end, step=1):
    """Returns a list of numbers beginning from start and
       incremented by step to end (with end excluded).

      start: an integer specifies the start of the range.

      end: an integer specifies the end of the range.

      step: an integer specifies the number to increment by.
      """

    num = start
    result = []

    while num &lt; end:
        result.append(num)
        num += step

    return result


How can it be refactored and optimized ?

Notes:  


I'm a hobbyist and beginner (in Python in particular, and programming in general).
I'm not sure how the actual python implementation for this works but you could query the length of *args to assign the parameters to the right variables:

def Range(*args):
    len_args = len(args)
    if len_args == 2:
        args = args + (1,)
    elif len_args == 1:
        args = (0, args[0], 1)
    start, end, step = args
    ...


In addition I would make this a generator (similar to how it is in python 3.x):

def Range(*args):
    len_args = len(args)
    if len_args == 2:
        args = args + (1,)
    elif len_args == 1:
        args = (0, args[0], 1)
    start, end, step = args

    while start &lt; end:
        yield start
        start += step