[转载] python字典类方法

本文详细介绍了Python字典的popitem方法,该方法用于移除并返回字典中的一个键值对。当字典为空时,调用popitem会引发KeyError。此外,还列举了其他如clear、copy、get等方法,帮助理解字典的各种操作。
摘要由CSDN通过智能技术生成

参考链接: Python字典dictionary| popitem方法

class dict(object):

    """

    dict() -> new empty dictionary

    dict(mapping) -> new dictionary initialized from a mapping object's

        (key, value) pairs

    dict(iterable) -> new dictionary initialized as if via:

        d = {}

        for k, v in iterable:

            d[k] = v

    dict(**kwargs) -> new dictionary initialized with the name=value pairs

        in the keyword argument list.  For example:  dict(one=1, two=2)

    """

    def clear(self): # real signature unknown; restored from __doc__

        """ D.clear() -> None.  Remove all items from D. """

        pass

 

 

 

    def copy(self): # real signature unknown; restored from __doc__

        """ D.copy() -> a shallow copy of D """

        pass

 

 

 

    @staticmethod # known case

    def fromkeys(*args, **kwargs): # real signature unknown

        """ Returns a new dict with keys from iterable and values equal to value. """

        pass

 

 

 

    def get(self, k, d=None): # real signature unknown; restored from __doc__

        """ D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None. """

        pass

 

 

 

    def items(self): # real signature unknown; restored from __doc__

        """ D.items() -> a set-like object providing a view on D's items """

        pass

 

 

 

    def keys(self): # real signature unknown; restored from __doc__

        """ D.keys() -> a set-like object providing a view on D's keys """

        pass

 

 

 

    def pop(self, k, d=None): # real signature unknown; restored from __doc__

        """

        D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

        If key is not found, d is returned if given, otherwise KeyError is raised

        """

        pass

 

 

 

    def popitem(self): # real signature unknown; restored from __doc__

        """

        D.popitem() -> (k, v), remove and return some (key, value) pair as a

        2-tuple; but raise KeyError if D is empty.

        """

        pass

 

 

 

    def setdefault(self, k, d=None): # real signature unknown; restored from __doc__

        """ D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D """

        pass

 

 

 

    def update(self, E=None, **F): # known special case of dict.update

        """

        D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.

        If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]

        If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v

        In either case, this is followed by: for k in F:  D[k] = F[k]

        """

        pass

 

 

 

    def values(self): # real signature unknown; restored from __doc__

        """ D.values() -> an object providing a view on D's values """

        pass

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值