首页 > 代码库 > Python中POP()的区别
Python中POP()的区别
Python中列表,字典和Set都有pop函数,但参数略有区别如下:以下参数基于Python 3.4.1
1. List
1 >>> help(list.pop)2 Help on method_descriptor:3 4 pop(...)5 L.pop([index]) -> item -- remove and return item at index (default last).6 Raises IndexError if list is empty or index is out of range.
2. Dict
1 >>> help(dict.pop)2 Help on method_descriptor:3 4 pop(...)5 D.pop(k[,d]) -> v, remove specified key and return the corresponding value.6 If key is not found, d is returned if given, otherwise KeyError is raised
3. Set
1 >>> help(set.pop)2 Help on method_descriptor:3 4 pop(...)5 Remove and return an arbitrary set element.6 Raises KeyError if the set is empty.
Python中POP()的区别
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。