Metoda pop() slovníku Pythonu
Příklad
Odeberte "model" ze slovníku:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
car.pop("model")
print(car)
Definice a použití
Metoda pop()
odstraní zadanou položku ze slovníku.
Hodnota odebrané položky je návratová hodnota pop()
metody, viz příklad níže.
Syntax
dictionary.pop(keyname, defaultvalue)
Hodnoty parametrů
Parameter | Description |
---|---|
keyname | Required. The keyname of the item you want to remove |
defaultvalue | Optional. A value to return if the specified key do not exist. If this parameter is not specified, and the no item with the specified key is found, an error is raised |
Další příklady
Příklad
Hodnota odebrané položky je návratová hodnota metody pop():
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.pop("model")
print(x)