파이썬 사전 pop() 메서드
예시
사전에서 "모델" 제거:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
car.pop("model")
print(car)
정의 및 사용
메서드 는 pop()
사전에서 지정된 항목을 제거합니다.
제거된 항목의 값은 pop()
메서드의 반환 값입니다. 아래 예를 참조하세요.
통사론
dictionary.pop(keyname, defaultvalue)
매개변수 값
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 |
더 많은 예
예시
제거된 항목의 값은 pop() 메서드의 반환 값입니다.
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.pop("model")
print(x)