計算集合元素個數(shù)
語法:len(set)
計算集合 set 元素個數(shù)。
>>> thisset = set(("Google", "Runoob", "Taobao"))
>>> len(thisset)
3
清空集合
語法:set.clear()
清空集合 set
>>> thisset = set(("Google", "Runoob", "Taobao"))
>>> thisset.clear()
>>> print(thisset)
set()
判斷元素是否在集合中存在
語法:x in set
判斷元素 x 是否在集合 set 中冯丙,存在返回 True,不存在返回 False
>>>thisset = set(("Google", "Runoob", "Taobao"))
>>> "Runoob" in thisset
True
>>> "Facebook" in thisset
False