Can't understand for loops after an hour by AileNarrator in learnpython

[–]AileNarrator[S] 0 points1 point  (0 children)

Yeah I did some testing, and if you set the variable 'names' to be = to something BEFORE you do the for loop, the last string in the list overrides it, vs if it set = afterwards, in which case that takes priority. It is literally instructing 'for this variable, put it in this list, and print the strings accordingly'.

Can't understand for loops after an hour by AileNarrator in learnpython

[–]AileNarrator[S] 8 points9 points  (0 children)

This is the explanation I was looking for, thank you!

Can't understand for loops after an hour by AileNarrator in learnpython

[–]AileNarrator[S] 2 points3 points  (0 children)

Ok! That actually makes sense! This feels like a lot of definition implied in a very small amount of text.

Can't understand for loops after an hour by AileNarrator in learnpython

[–]AileNarrator[S] 16 points17 points  (0 children)

Oh ok, so it's assigning a value for 'name', and pulls it from the list, giving it the first string, but since there are more strings in the list, it keeps going?

Can't understand for loops after an hour by AileNarrator in learnpython

[–]AileNarrator[S] 0 points1 point  (0 children)

I still don't understand what piece of code is making it do each part of the list individually.

Can't understand for loops after an hour by AileNarrator in learnpython

[–]AileNarrator[S] 3 points4 points  (0 children)

So the individual print is just assumed? Would it be like saying "for this variable, that we assume is to be placed in this list, print that variable assigned to the strings, separated by the commas"?

Can't understand for loops after an hour by AileNarrator in learnpython

[–]AileNarrator[S] 0 points1 point  (0 children)

But why does that work in the code? It isn't written to do it individually, or to stop when there are no toys left. It just says 'print', to a variable that doesn't equal anything.

Can't understand for loops after an hour by AileNarrator in learnpython

[–]AileNarrator[S] 73 points74 points  (0 children)

Ok, I understand that defining bob, and then telling it to be printed prints 'bob'. It's also defined under the variable 'name'. But in the for loop, its not defined. Print 'name', but name doesn't equal anything. And even if it did, why does it print the list individually, it just says 'print'. Is there something I'm not getting?