본문으로 건너뛰기
Minsing Log
뒤로 가기

Dictionary.pop(Key)

Programming & CS

헷갈렸던 부분

Dictionary pop을 한다면?

ex)

# random sales dictionary
sales = { 'apple': 2, 'orange': 3, 'grapes': 4 }

element = sales.pop('apple')

print('The popped element is:', element)
print('The dictionary is:', sales)

Output

The popped element is: 2
The dictionary is: {'orange': 3, 'grapes': 4}

Syntax

Syntax of Dictionary pop() The syntax of pop() method is

dictionary.pop(key[, default])

pop() method takes two parameters:

Return value from pop()

The pop() method returns:

If key is found - removed/popped element from the dictionary If key is not found - value specified as the second argument (default) If key is not found and default argument is not specified - KeyError exception is raised

출처: https://www.programiz.com/python-programming/methods/dictionary/pop

공개 여정 구독

글이 올라오면 이메일로 보내드릴게요.

개발, 창업, 배움, 실패와 회고를 짧고 솔직하게 기록합니다. 검색으로 스쳐가는 독자가 아니라 여정을 따라오는 팬을 만들기 위한 뉴스레터입니다.

뉴스레터는 준비 중입니다. 그동안 RSS 로 구독하거나 이메일 로 알림을 요청해 주세요.


이 글 공유하기:

댓글

GitHub 계정으로 로그인해 댓글을 남길 수 있습니다.


이전 글
얇은 복사 copy() , 깊은 복사 deepcopy()
다음 글
Sorted() parameter key 값 lambda에 대하여