Noob question about for Loop

Hi. I’m studying Python and I used to be active in this forum so why not ask here.

I’m studying python and tried doing “for” loop codes.

list = [“a”, “b”, “c”, “d”, “e”]

for x in list:
print list

But what I’m only getting is the letter “e” at the end. Then all of the list gets messed up and only remains “e”.

Please help me. Thank you.

Well, there must be some other code because what you posted shouldn’t have the kind of side effect you’re getting. This:

list = ["a", "b", "c", "d", "e"]
for x in list:
     print list

should result in the following output:

['a', 'b', 'c', 'd', 'e']
['a', 'b', 'c', 'd', 'e']
['a', 'b', 'c', 'd', 'e']
['a', 'b', 'c', 'd', 'e']
['a', 'b', 'c', 'd', 'e']

That the list variable printed five times on screen.
Of course it might not be what you intended to do. My wild guess is that you wanted to print “x” instead of “list” (as the for iterates over the content of the list, the x variable points to the value of each element in the list, once per element).
Anyways, with that code (and only that), you should get the result I posted.

hint:

calling a variable “list” is no good idea, as you mangle the build-in object type “list”. In a narrow context it is fine, but can still lead to hard-to-investigate issues.