For One and All, lesson clarification [SOLVED]


#1

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

#2

Hi,
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.


#3

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


#4

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?


#5

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? ? ?


#6

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.


#7

Do you understand now?


#8

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.


#9

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?


#10

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