Python 新增集合項
新增集合項
要向集合新增單個專案,請使用 add()
方法。
要向集合新增多個專案,請使用 update()
方法。
示例
使用 add()
方法向集合新增一個專案
thisset = {"apple", "banana", "cherry"}
thisset.add("orange")
print(thisset)
自己動手試一試 »
示例
使用 update()
方法向集合新增多個專案
thisset = {"apple", "banana", "cherry"}
thisset.update(["orange", "mango", "grapes"])
print(thisset)
自己動手試一試 »