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 thelist
. Usinglist[x]
is actually picking the element in thex
position from thelist
.“ x”代表一个数字,随着for循环的每次迭代而变化。当您执行list [x]时,您将在列表中获得第x个数字,从0开始。