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://www.codercto.com/courses/l/10.html

查看所有标签

Discrete Mathematics and Its Applications

Discrete Mathematics and Its Applications

Kenneth H Rosen / McGraw-Hill Science/Engineering/Math / 2003-04-22 / USD 132.81

Discrete Mathematics and its Applications is a focused introduction to the primary themes in a discrete mathematics course, as introduced through extensive applications, expansive discussion, and deta......一起来看看 《Discrete Mathematics and Its Applications》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

MD5 加密
MD5 加密

MD5 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具