For One and All


#1

I got this question correct after checking on the forum essentially i just looked at the back of the question book for the answer.

I just don’t understand the logic behind what i have done. I’ve used the variable number however i haven’t given it a value which i thought i would’ve had to do for it to work.

my_list = [1,9,3,8,5,7]

for number in my_list:

print 2 * number

Essentially i’m asking what does the variable number represent in the code i have written?


#2

the loop iterator (number) is defined in the for loop, python then assigns the first value in list to the variable, execute the code in for loop code block, then assigns next value to the loop iterator, executes the for loop code block, and so on, until it finished going over all the values in the list


#3

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