Python - 访问集合项
访问集合项
您无法通过索引或键来访问集合中的项。
但是,您可以使用 `for` 循环遍历集合项,或者使用 `in` 关键字来查询指定值是否存在于集合中。
实例
检查集合中是否不包含"banana":
thisset = {"apple", "banana", "cherry"}
print("banana"
not in thisset)
亲自试一试 »
更改项目
集合创建后,您无法更改其中的项目,但可以添加新项目。
您无法通过索引或键来访问集合中的项。
但是,您可以使用 `for` 循环遍历集合项,或者使用 `in` 关键字来查询指定值是否存在于集合中。
检查集合中是否不包含"banana":
thisset = {"apple", "banana", "cherry"}
print("banana"
not in thisset)
亲自试一试 »
集合创建后,您无法更改其中的项目,但可以添加新项目。
