Help with using range method


#1

I wonder if somebody can explain this to me please. In the following example…

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

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

I’m supposed to fill in the blank using the range method in a way that would result in a list being printed that looks like this…

[0,1,2]

Since range appears to only use integer steps and the functions multiplies by 2 then how can I get the desired result? I seems that if the step could be 0.5 (not an integer) then this would be easy. I could just do range(0,1.5,0.5) or something like that.


#2

That is output of range(3).

Aside

range() is not a method, as such, but a built-in function.


#3

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