鱼C论坛

 找回密码
 立即注册
查看: 2689|回复: 12

[已解决]python3中集合的pop()方法到底是不是随机弹出元素

[复制链接]
发表于 2020-4-26 02:47:30 | 显示全部楼层
pop() parameters
The pop() method takes a single argument (index).
The argument passed to the method is optional. If not passed, the default index -1 is passed as an argument (index of the last item).
If the index passed to the method is not in range, it throws IndexError: pop index out of range exception.

也就是说,当不给定位置参数时,默认为-1,即列表最后一个数
举个简单例子
  1. l=[1,2,3,4]
  2. print(l.pop())

  3. l=[1,2,3,4]
  4. print(l.pop(-1))
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-21 03:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表