码迷,mamicode.com
首页 > 编程语言 > 详细

Python中POP()的区别

时间:2014-08-29 00:06:09      阅读:567      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   ar   div   log   sp   on   

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()的区别

标签:des   style   blog   color   ar   div   log   sp   on   

原文地址:http://www.cnblogs.com/xpal0ne/p/3943550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!