💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
add()函数 \>>> s2={123,"hello",123,"124"} \>>> s3=set(s2) \>>> s3 {123, 'hello', '124'} \>>> s3.add("000") \>>> s3 {'000', 123, 'hello', '124'} \>>> update函数 \>>> s {'e', 'l', 'o', 'h'} \>>> s.update(s2) \>>> s {'l', 'hello', 'e', 123, 'o', 'h', '124'} \>>> s2 {123, 'hello', '124'} \>>> pop、remove、discard、clear pop() \#从集合中任选一个删除,并返回该值 \>>> s {'l', 'hello', 'e', 123, 'o', 'h', '124'} \>>> s.pop() 'l' \>>> s {'hello', 'e', 123, 'o', 'h', '124'} \>>> s.pop() 'hello' \>>> remove() #删除集合中特定的元素 \>>> s.remove("e") \>>> s {123, 'o', 'h', '124'} \>>> discard() \#查找元素是否在集合中,若存在,就删除,若不在,啥也不做 \>>> s.discard("h") \>>> s {123, 'o', '124'} \>>> clear() \#删除集合中的所有元素 \>>> s {123, 'o', '124'} \>>> s.clear() \>>> s set() \>>>