For One and All, lesson clarification [SOLVED]


I tried both sets of codes, and they print the same results on the console.
Is there a reason why at default it uses number, instead of numbers ???

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

for number in my_list:
    print 2 * number

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

for numbers in my_list:
    print 2 * numbers


I don't quite get what you are asking. :confused: Are you having problems with one set of code or what? And I assume that they use number just becuase they want to and not for any special reason.


I want to know the difference between using "for number" vs "for numbers"
Because the original code used for number, and I personally tried for numbers which prints the same results in console


It doesn't have a difference, you could say potato and it still would be the same. The part that does matter is my_list. That identifies what the for loop should be using when it is looping. :slight_smile: Does that answer your question?


I guess I was wondering how the console associate "number" or "potato" you say to [1, 9, 3, 8, 5, 7]?
Because now I'm getting this

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

for potato in my_list:
print 2 * potato

will print same result? ? ?


Yup, number is really just a variable in the for loop, it's not registered in Python as a specific variable if that's what you were thinking. That's why it's wouldn't matter what you wrote in that part of the line. It associates potato or number as each item in the list you are giving it.


Do you understand now?


Wow, this is very helpful, I initially thought the word "number" automatically registered to integers in python and that's why it was by default the case.


Yeah that's not registered as integers, although if you are doing it on Codecademy, they may want you to write specific stuff, so the lesson checker may recognize it, but it still is the same concept. :slight_smile: If you aren't confused anymore, then can you edit your title to say solved so people know you don't need help anymore?


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