Python 何时使用append?

Python 何时使用append?,python,Python,我最近开始用Python3.5.2编程(我大约三年前学过C++但从那时起我就没用过),我不理解 “.append()” 也许问题是我不是以英语为母语的人 有人能给我解释一下这个概念吗 编辑:谢谢。我不能让这个代码工作。基本上,我希望用户输入日、月、年并将它们保存到GDO中。我犯了什么错 from tkinter import * root = Tk () root.title("Calendar") root.geometry("300x300") GDO1 = ['Day', 'Mont

我最近开始用Python3.5.2编程(我大约三年前学过C++但从那时起我就没用过),我不理解 “.append()”

也许问题是我不是以英语为母语的人

有人能给我解释一下这个概念吗

编辑:谢谢。我不能让这个代码工作。基本上,我希望用户输入日、月、年并将它们保存到GDO中。我犯了什么错

from tkinter import *


root = Tk ()
root.title("Calendar")
root.geometry("300x300")

GDO1 = ['Day', 'Month', 'Year']
GDO = []
for w in range (3):

     en = Entry(root)
     lab = Label(root, text = GDO1[w])
     lab.grid(row=w+1, column=0, sticky = W)
     en.grid(row=w+1, column=1, sticky = W)
     GDO.append(en)

buttonGDO = Button (root, text="Submit", command=GDO.append(en) and print   (GDO))
buttonGDO.grid(row=4)


root.mainloop

您有一个列表,例如[1,2,3] 如果要添加其他元素,请使用“附加”:

list = [1, 2, 3]
list.append(4)

append函数将对象追加到现有列表中

请参阅文档:

编辑: 在您的特定示例中,问题不在于append
mainloop
是一个函数调用,因此您需要这样调用它,并用括号括起来:


root.mainloop()

>>> list = ['one', 'two', 'three']
>>> list
['one', 'two', 'three']
>>> list.append('four')
>>> list
['one', 'two', 'three', 'four']

这看起来确实是一个典型的RTFM案例。。。
consider if you have List = [1,2,3,4]
#append function - Adds an item to the end of the list.
>>>L = [1,2,3,4]
>>>L.append(5)
>>>print(L)
>>>[1,2,3,4,5]