Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

get method in Python dictionary

# without default
{"name": "Victor"}.get("name")
# returns "Victor"

{"name": "Victor"}.get("nickname")
# returns None

# with default
{"name": "Victor"}.get("nickname", "nickname is not a key")
# returns "nickname is not a key"
Source by www.codecademy.com #
 
PREVIOUS NEXT
Tagged: #method #Python #dictionary
ADD COMMENT
Topic
Name
3+3 =