简体   繁体   English

遍历列表

[英]Iterate through a list

Very simple problem. 很简单的问题。 Sorry I am new. 对不起,我是新来的。 I have this code below: 我在下面的代码:

list = ['edward', 'jason', 'john']
for i in list:
    print list

and it produces: 它产生:

john

Why do I only get the last name? 为什么我只得到姓氏? I want all of them. 我要所有人 ie. 即。

edward
jason
john

You should print i not list : 您应该打印ilist

lis = ['edward', 'jason', 'john']    #don't use list as a variable name
for i in lis:
    print i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM