共計 288 個字符,預計需要花費 1 分鐘才能閱讀完成。
要將數(shù)字添加到列表中,可以使用列表的 append()
方法。該方法用于在列表末尾添加一個元素。
以下是示例代碼:
numbers = [1, 2, 3, 4]
new_number = 5
numbers.append(new_number)
print(numbers) # 輸出: [1, 2, 3, 4, 5]
在上述代碼中,我們定義了一個名為 numbers
的列表,其中包含一些數(shù)字。然后,我們定義一個新的數(shù)字 new_number
。使用append()
方法將 new_number
添加到 numbers
列表的末尾。最后,我們打印輸出列表的內(nèi)容,可以看到新的數(shù)字已經(jīng)被添加到了列表中。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完