ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
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() \>>>