Dizionario Python metodo get()
Esempio
Ottieni il valore dell'articolo "modello":
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("model")
print(x)
Definizione e utilizzo
Il get()
metodo restituisce il valore dell'elemento con la chiave specificata.
Sintassi
dictionary.get(keyname, value)
Valori dei parametri
Parameter | Description |
---|---|
keyname | Required. The keyname of the item you want to return the value from |
value | Optional. A value to return if the specified key does not exist. Default value None |
Altri esempi
Esempio
Prova a restituire il valore di un articolo che non esiste:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("price", 15000)
print(x)