Python中POP()的区别

时间:2014-08-29 00:06:09   收藏:0   阅读:567

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.

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!