Passing a range into a function


#1



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!


#2

python documentation - range

there you go.

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

range(3)

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


#3

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