Built-in methods of Python 3.6 dictionary

1、dict.clear(self)

    delete all elements in the dictionary

2、dict.copy(self)

    Returns a shallow copy of the dictionary, copying the parent object, but not copying the internal child objects of the object

3、dict.fromkeys(self, seq[, value])

    The elements in the sequence seq are used as the keys of the dictionary, and the value is the initial value corresponding to all the keys of the dictionary

4、dict.get(self, k, d=None)

    Returns the value of the specified key k, or None if the value is not in the dictionary

5、dict.items(self)

    Returns an iterable array of (key, value) tuples

6、dict.keys(self)

    Returns all keys of a dictionary as a list

7、dict.pop(self, k, d=None)

    Deletes the value corresponding to the given key key in the dictionary, and returns the deleted value. The key value must be given. Otherwise, return the default value

8、dict.popitem(self)

    Randomly returns and deletes a key and value pair from the dictionary (generally deletes the pair at the end)

9、dict.setdefault(self, k, d=None)

    If k is in the dictionary, return the corresponding value. If it is not in the dictionary, insert key and set default value default, and return default, default default value is None

10、dict.update(self, E=None, **F)

    Update the key/value pairs of dictionary F into dict

11、dict.values(self)

    Returns all values ​​in the dictionary as a list

 

 

remove dictionary element  

  del dict [ 'Name' ] # delete key 'Name'    dict . clear () # clear dictionary del dict # delete dictionary     

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325214719&siteId=291194637