파이썬 사전 get() 메서드
예시
"모델" 항목의 값을 가져옵니다.
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)