根据文档:简单的python列出了问题
list.append(x): Add an item to the end of the list
所以,如果我做的:
list = []
list.append("banana")
print list[0] --> which is suppose to print the FIRST item of the list
> banana
到目前为止好,但是如果现在我附上另一个项目:
list.append("apple")
print list[0]
apple
是不是应该追加到列表的最后?如何在追加时保留列表的顺序?我应该如何打印列表中的第一个和最后一个项目 - 按照它们添加到它的顺序?
感谢
您不应该使用名称'list'作为变量名称。但是,你必须在你的问题中遗漏一些东西。追加add的元素到列表的后面 – GWW 2011-03-23 19:47:04
出于好奇,你实际上并没有在你的代码中使用变量名'list',对吗? Big no-no – 2011-03-23 19:47:32
@ S.Lott,我的推理是为其他可能试图回答问题的用户提供警告,因为我仍然需要10分钟才能接受答案。 – relima 2011-03-23 20:05:57