Python3 集合Python3 集合 remove() 方法本页总览Python3 集合 remove() 方法描述remove() 方法用于移除集合中的指定元素。该方法不同于 discard() 方法,因为 remove() 方法在移除一个不存在的元素时会发生错误,而 discard() 方法不会。语法remove() 方法语法:set.remove(item)参数item -- 要移除的元素返回值没有返回值。实例移除元素 banana:实例 1fruits = {"apple", "banana", "cherry"} fruits.remove("banana") print(fruits)输出结果为:{'cherry', 'apple'}