u/AileNarrator

Can't understand for loops after an hour

I've looked through other posts on this, and none of them address my problem, and neither do any tutorials. I've tried to understand and I just can't wrap my head around it.

names = ['bob','jim','bill','kate']
for name in names:
print(name)

I see stuff this thrown around a bunch but this is complete nonsense to me. The word 'name' quite literally is not in the list. For 'name' in names, print 'name'? It doesn't print name though, it prints the stuff in the list. And even if the word name were in the list, it doesn't print the list, it does it all individually, even though there's no indication on why it would do that. What don't I get??

Edit: A few people have explained that the code is essentially putting "name' into the list to assign it to a string within that list, and then printing the result of that, until the list has run out. Thanks!

reddit.com
u/AileNarrator — 17 hours ago