-
[Python tutorial] 22. Dictionary methods코딩/Python 2022. 12. 21. 17:27728x90
dictionary.clear()
Removes all the elements from the dictionary
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car.clear()
dictionary.copy()
Returns a copy of the dictionary
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.copy()
dict.fromkeys(keys, value)
Returns a dictionary with the specified keys and value
x = ('key1', 'key2', 'key3') y = 0 thisdict = dict.fromkeys(x, y)
dictionary.get(keyname, value)
Returns the value of the specified key
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.get("model")
dictionary.items()
Returns a list containing a tuple for each key value pair
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.items()
dictionary.keys()
Returns a list containing the dictionary's keys
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.keys() print(x)
dictionary.pop(keyname, defaultvalue)
Removes the element with the specified key
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car.pop("model")
dictionary.popitem()
Removes the last inserted key-value pair
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car.popitem()
dictionary.setdefault(keyname, value)
Returns the value of the specified key. If the key does not exist: insert the key, with the specified value
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.setdefault("model", "Bronco")
dictionary.update(iterable)
Updates the dictionary with the specified key-value pairs
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } car.update({"color": "White"})
dictionary.values()
Returns a list of all the values in the dictionary
car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.values()
728x90'코딩 > Python' 카테고리의 다른 글
[Python tutorial] 24. Set Methods (0) 2022.12.21 [Python tutorial] 23. Tuple Methods (0) 2022.12.21 [Python tutorial] 21. List/Array methods (0) 2022.12.21 [Python tutorial] 20. String methods (1) 2022.12.21 [Python tutorial] 19. Built-in Function (0) 2022.12.21