Python Sözlüğü get() Yöntemi
Örnek
"Model" öğesinin değerini alın:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("model")
print(x)
Tanım ve Kullanım
Yöntem get()
, belirtilen anahtarla öğenin değerini döndürür.
Sözdizimi
dictionary.get(keyname, value)
Parametre Değerleri
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 |
Daha fazla örnek
Örnek
Var olmayan bir öğenin değerini döndürmeye çalışın:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("price", 15000)
print(x)