Passing a range into a function


What exactly is happening here? Also, if anyone can link me to a better understanding of ranges that'd be sick.

def my_function(x):
    for i in range(0, len(x)):
        x[i] = x[i] * 2
    return x

print my_function(range(3)) # Add your range between the parentheses!


python documentation - range

there you go.

range is a built in function, so when you do this:


you have a function call to execute a built in function. The function will execute, and return the list.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.