Python Set pop() 方法
Python 3 教程
· 2019-02-06 20:27:39
描述
pop() 方法用于随机移除一个元素。
语法
pop() 方法语法:
set.pop()
参数
- 无
返回值
返回移除的元素。
实例
随机移除一个元素:
实例 1
fruits = {"apple", "banana", "cherry"}
fruits.pop()
print(fruits)
输出结果为:
{'apple', 'banana'}
输出返回值:
实例 1
fruits = {"apple", "banana", "cherry"}
x = fruits.pop()
print(x)
输出结果为:
banana
点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html