Python Set remove() 方法

Python 3 教程 · 2019-02-06 20:44:34

描述

remove() 方法用于移除集合中的指定元素。

该方法不同于 discard() 方法,因为 remove() 方法在移除一个不存在的元素时会发生错误,而 discard() 方法不会。

语法

remove() 方法语法:

set.remove(item)

参数

  • item -- 要移除的元素

返回值

返回移除的元素。

实例

移除元素 banana:

实例 1

fruits = {"apple", "banana", "cherry"} fruits.remove("banana") print(fruits)

输出结果为:

{'cherry', 'apple'}

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Wikis For Dummies

Wikis For Dummies

Dan Woods、Peter Thoeny / For Dummies / 2007-7-23 / USD 24.99

Corporations have finally realized the value of collaboration tools for knowledge sharing and Wiki is the open source technology for creating collaborative Web sites, as either a public site on the In......一起来看看 《Wikis For Dummies》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具