python基本数据类型之dict

 

 


 dict: 字典

  基本操作 :

    • 循环
    • 长度

    

  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 
  4 
  5 """ 基本数据类型之dict """
  6 
  7 
  8 class dict(object):
  9     """
 10     dict() -> new empty dictionary
 11     dict(mapping) -> new dictionary initialized from a mapping object's
 12         (key, value) pairs
 13     dict(iterable) -> new dictionary initialized as if via:
 14         d = {}
 15         for k, v in iterable:
 16             d[k] = v
 17     dict(**kwargs) -> new dictionary initialized with the name=value pairs
 18         in the keyword argument list.  For example:  dict(one=1, two=2)
 19     """
 20     def clear(self): # real signature unknown; restored from __doc__
 21         """ 清空字典 """
 22         """ D.clear() -> None.  Remove all items from D. """
 23         pass
 24 
 25     def copy(self): # real signature unknown; restored from __doc__
 26         """ 拷贝字典 浅拷贝 """
 27         """ D.copy() -> a shallow copy of D """
 28         pass
 29 
 30     @staticmethod # known case
 31     def fromkeys(*args, **kwargs): # real signature unknown
 32         """ 创建一个新字典,以序列 seq 中元素做字典的键,value 为字典所有键对应的初始值 """
 33         """ Returns a new dict with keys from iterable and values equal to value. """
 34         pass
 35 
 36     def get(self, k, d=None): # real signature unknown; restored from __doc__
 37         """ 根据键来获取值 """
 38         """ D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None. """
 39         pass
 40 
 41     def items(self): # real signature unknown; restored from __doc__
 42         """ 以列表的形式返回字典的键值对,每一对键值对都是一个元组,键在前,值在后 """
 43         """ D.items() -> a set-like object providing a view on D's items """
 44         pass
 45 
 46     def keys(self): # real signature unknown; restored from __doc__
 47         """ 以列表的形式返回字典里的键 """
 48         """ D.keys() -> a set-like object providing a view on D's keys """
 49         pass
 50 
 51     def pop(self, k, d=None): # real signature unknown; restored from __doc__
 52         """ 删除对应的键的值并返回,如果键不存在,则返回d """
 53         """
 54         D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
 55         If key is not found, d is returned if given, otherwise KeyError is raised
 56         """
 57         pass
 58 
 59     def popitem(self): # real signature unknown; restored from __doc__
 60         """ 随机删除一对键值对并返回 """
 61         """
 62         D.popitem() -> (k, v), remove and return some (key, value) pair as a
 63         2-tuple; but raise KeyError if D is empty.
 64         """
 65         pass
 66 
 67     def setdefault(self, k, d=None): # real signature unknown; restored from __doc__
 68         """ 增加键值对,k是键,d是值,默认是None,当键存在时,返回对应的值 """
 69         """ D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D """
 70         pass
 71 
 72     def update(self, E=None, **F): # known special case of dict.update
 73         """ 更新字典,以一个字典作为参考来更新字典 """
 74         """
 75         D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.
 76         If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]
 77         If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
 78         In either case, this is followed by: for k in F:  D[k] = F[k]
 79         """
 80         pass
 81 
 82     def values(self): # real signature unknown; restored from __doc__
 83         """ 返回所有的值 """
 84         """ D.values() -> an object providing a view on D's values """
 85         pass
 86 
 87     def __contains__(self, *args, **kwargs): # real signature unknown
 88         """ True if D has a key k, else False. """
 89         pass
 90 
 91     def __delitem__(self, *args, **kwargs): # real signature unknown
 92         """ Delete self[key]. """
 93         pass
 94 
 95     def __eq__(self, *args, **kwargs): # real signature unknown
 96         """ Return self==value. """
 97         pass
 98 
 99     def __getattribute__(self, *args, **kwargs): # real signature unknown
100         """ Return getattr(self, name). """
101         pass
102 
103     def __getitem__(self, y): # real signature unknown; restored from __doc__
104         """ x.__getitem__(y) <==> x[y] """
105         pass
106 
107     def __ge__(self, *args, **kwargs): # real signature unknown
108         """ Return self>=value. """
109         pass
110 
111     def __gt__(self, *args, **kwargs): # real signature unknown
112         """ Return self>value. """
113         pass
114 
115     def __init__(self, seq=None, **kwargs): # known special case of dict.__init__
116         """
117         dict() -> new empty dictionary
118         dict(mapping) -> new dictionary initialized from a mapping object's
119             (key, value) pairs
120         dict(iterable) -> new dictionary initialized as if via:
121             d = {}
122             for k, v in iterable:
123                 d[k] = v
124         dict(**kwargs) -> new dictionary initialized with the name=value pairs
125             in the keyword argument list.  For example:  dict(one=1, two=2)
126         # (copied from class doc)
127         """
128         pass
129 
130     def __iter__(self, *args, **kwargs): # real signature unknown
131         """ Implement iter(self). """
132         pass
133 
134     def __len__(self, *args, **kwargs): # real signature unknown
135         """ Return len(self). """
136         pass
137 
138     def __le__(self, *args, **kwargs): # real signature unknown
139         """ Return self<=value. """
140         pass
141 
142     def __lt__(self, *args, **kwargs): # real signature unknown
143         """ Return self<value. """
144         pass
145 
146     @staticmethod # known case of __new__
147     def __new__(*args, **kwargs): # real signature unknown
148         """ Create and return a new object.  See help(type) for accurate signature. """
149         pass
150 
151     def __ne__(self, *args, **kwargs): # real signature unknown
152         """ Return self!=value. """
153         pass
154 
155     def __repr__(self, *args, **kwargs): # real signature unknown
156         """ Return repr(self). """
157         pass
158 
159     def __setitem__(self, *args, **kwargs): # real signature unknown
160         """ Set self[key] to value. """
161         pass
162 
163     def __sizeof__(self): # real signature unknown; restored from __doc__
164         """ D.__sizeof__() -> size of D in memory, in bytes """
165         pass
166 
167     __hash__ = None

 

 

 

 

 

 

 

posted @ 2018-07-30 22:04  Sorcerer  阅读(139)  评论(0)    收藏  举报