+ 3
Why is output 123123 instead of 123
mylist = [] mylist.append(1) mylist.append(2) mylist.append(3) print(mylist[0]) # prints 1 print(mylist[1]) # prints 2 print(mylist[2]) # prints 3 # prints out 1,2,3 for x in mylist: Â Â Â Â print x
3 Answers
+ 5
Of course it will give you
1
2
3
1
2
3
You are first printing all the elements of the list serperatley. Then you are using another for loop to print them again. It's like repeating the same process. So first "123" for the individual print statements and another "123" for the for loop one.
You can see this...
https://code.sololearn.com/ch7YvObuOqLu/?ref=app
+ 3
says so in the comments, it prints out each element in the list one by one before printing out the entire list
+ 1
How does x represent all numbers in list?