首页 > 代码库 > 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()的区别