简单列表理解问题python

list=(1,2,3,4)
for x in range(len(list)):
    print(list[x])

1 2 3 4 but print(list) repeats the whole list 4 times ie

1,2,3,4
1,2,3,4
1,2,3,4

how does the x in the print(list[x]) cause only single numbers to come out? Like how could you put what the [x] is doing in english?

评论
红颜祸水
红颜祸水

x represents the index within the list. Using list[x] is actually picking the element in the x position from the list.

点赞
评论
uaut
uaut

“ x”代表一个数字,随着for循环的每次迭代而变化。当您执行list [x]时,您将在列表中获得第x个数字,从0开始。

点赞
评论