Python使用示例设置pop()方法
设定pop()方法
pop()方法用于从集合中删除随机元素,该方法将与此集合一起调用,并从集合中删除随机元素。
语法:
set_name.pop()
Parameter(s):
它不接受任何参数。
返回值:
该方法的返回类型是元素的类型,它返回移除/弹出的元素。
示例
#Python使用示例设置pop()方法
#宣布布景
cars = {"Porsche", "Audi", "Lexus", "Mazda", "Lincoln"}
nums = {100, 200, 300, 400, 500}
#在移除之前打印套件
print("Before the calling pop() method...")
print("cars: ", cars)
print("nums: ", nums)
#从集合中删除/弹出元素
x = cars.pop()
print(x, "is removed from cars")
x = cars.pop()
print(x, "is removed from cars")
x = cars.pop()
print(x, "is removed from cars")
x = nums.pop()
print(x, "is removed from nums")
x = nums.pop()
print(x, "is removed from nums")
x = nums.pop()
print(x, "is removed from nums")
#取出后打印套件
print("After the calling pop() method...")
print("cars: ", cars)
print("nums: ", nums)输出结果
Before the calling pop() method...
cars: {'Audi', 'Porsche', 'Lexus', 'Mazda', 'Lincoln'}
nums: {100, 200, 300, 400, 500}
Audi is removed from cars
Porsche is removed from cars
Lexus is removed from cars
100 is removed from nums
200 is removed from nums
300 is removed from nums
After the calling pop() method...
cars: {'Mazda', 'Lincoln'}
nums: {400, 500}热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短