根據文檔:簡單的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