filmov
tv
#Python# dictionary methods#

Показать описание
Here is a description of common Python dictionary methods:
clear(): Removes all items from the dictionary.
copy(): Returns a shallow copy of the dictionary.
fromkeys(seq, value): Creates a new dictionary with keys from seq and values set to value.
get(key, default): Returns the value for key if it exists in the dictionary, else returns default.
items(): Returns a view object that displays a list of a dictionary's key-value tuple pairs.
keys(): Returns a view object that displays a list of all the keys in the dictionary.
pop(key, default): Removes and returns the element with the specified key. If the key does not exist, it returns the default value if provided, otherwise, it raises a KeyError.
popitem(): Removes and returns the last inserted key-value pair in the dictionary.
setdefault(key, default): If the key is in the dictionary, it returns its value. If not, it inserts the key with a default value.
update(other): Updates the dictionary with the key-value pairs from other, overwriting existing keys.
values(): Returns a view object that displays a list of all the values in the dictionary.
Dictionaries in Python are mutable, unordered collections of key-value pairs, where keys must be immutable and unique. As of Python 3.7, dictionaries preserve insertion order.
clear(): Removes all items from the dictionary.
copy(): Returns a shallow copy of the dictionary.
fromkeys(seq, value): Creates a new dictionary with keys from seq and values set to value.
get(key, default): Returns the value for key if it exists in the dictionary, else returns default.
items(): Returns a view object that displays a list of a dictionary's key-value tuple pairs.
keys(): Returns a view object that displays a list of all the keys in the dictionary.
pop(key, default): Removes and returns the element with the specified key. If the key does not exist, it returns the default value if provided, otherwise, it raises a KeyError.
popitem(): Removes and returns the last inserted key-value pair in the dictionary.
setdefault(key, default): If the key is in the dictionary, it returns its value. If not, it inserts the key with a default value.
update(other): Updates the dictionary with the key-value pairs from other, overwriting existing keys.
values(): Returns a view object that displays a list of all the values in the dictionary.
Dictionaries in Python are mutable, unordered collections of key-value pairs, where keys must be immutable and unique. As of Python 3.7, dictionaries preserve insertion order.