共計(jì) 263 個(gè)字符,預(yù)計(jì)需要花費(fèi) 1 分鐘才能閱讀完成。
在 Python 中,可以使用 append() 方法向數(shù)組中添加元素。append() 方法將元素添加到數(shù)組的末尾。
以下是一個(gè)示例代碼:
# 創(chuàng)建一個(gè)空數(shù)組
arr = []
# 使用 append() 方法向數(shù)組中添加元素
arr.append(1)
arr.append(2)
arr.append(3)
# 打印數(shù)組
print(arr) # 輸出結(jié)果:[1, 2, 3]
在上面的代碼中,我們首先創(chuàng)建了一個(gè)空數(shù)組 arr。然后,使用 append() 方法分別向數(shù)組中添加了整數(shù) 1、2 和 3。最后,打印數(shù)組的內(nèi)容,輸出結(jié)果為 [1, 2, 3]。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完