पायथन डिक्शनरी प्राप्त करें () विधि
उदाहरण
"मॉडल" आइटम का मूल्य प्राप्त करें:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("model")
print(x)
परिभाषा और उपयोग
get()
विधि निर्दिष्ट कुंजी के साथ आइटम का मान लौटाती है ।
वाक्य - विन्यास
dictionary.get(keyname, value)
पैरामीटर मान
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 |
और ज्यादा उदाहरण
उदाहरण
उस आइटम का मान वापस करने का प्रयास करें जो मौजूद नहीं है:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("price", 15000)
print(x)