何时使用append?

2024-05-31 23:36:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近在Python 3.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

Tags: text功能编程labcolumnrootgriden
3条回答
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]

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

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

Append非常简单,它只是向列表中添加或追加一个值。你知道吗

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

相关问题 更多 >