Python> dictionary> get ()> optional value

@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 1642 / 12833)

About the function get () that retrieves the elements of the Python Dictionary.

If not, you get the optional value, if you specified one:

>>> pythons.get('Mark', 'Not a Pythong')
'Not a Python'

An example when it is not included in dictionary "pythons".

I've tried.

http://ideone.com/zUP5Pu

mydic = {'7of9' : 'borg', 'Chakotay' : 'human', 'Janeway' : 'human'}
print(mydic.get('7of9', 'unknown'))
print(mydic.get('Chakotay', 'unknown'))
print(mydic.get('Tuvok', 'unknown'))

result


Success	time: 0 memory: 23352 signal:0
borg
human
unknown

Recommended Posts

Python> dictionary> get ()> optional value
Python dictionary
[Python] dictionary
Python dictionary
Replace dictionary value with Python> update ()
[Python] Memo dictionary
Python> dictionary> values ()> Get All Values by Using values ()
Convert Python> two value sequence to dictionary
[Python] Dictionary (hash)
Python basics: dictionary
Get multiple maximum keys in Python dictionary type
How to get dictionary type elements of Python 2.7
[Python] Get environment variables
Python Basic Course (7 Dictionary)
[Python] Get Qiita trends
Python3 List / dictionary memo
Python Dictionary Beginner's Guide
[Python3] Get date diff
Get date in Python
python get current time
Get the value selected in Selenium Python VBA pull-down
Get the value of a specific key in a list from the dictionary type in the list with Python
Get YouTube Comments in Python
Get country code with python
Python --bitflyer Get asset balance
Python list, for statement, dictionary
Create a dictionary in Python
Get last month in python
[python] Value of function object (?)
Get Youtube data with python
Get the value of a specific key up to the specified index in the dictionary list in Python
Get the value while specifying the default value from dict in Python
Get Terminal size in Python
[Python] numpy.empty initial value setting
Python> dictionary / collections> defaultdict () / Counter ()
Explicitly get EOF in python
How to get the last (last) value in a list in Python
Get index of nth largest / smallest value in list in Python
Get thread ID with python
Avoid KeyError in python dictionary
Get started with Python! ~ ② Grammar ~
[python] Get quotient and remainder
Get stock price with Python
Get Evernote notes in Python
python> Get substring> print serial [5:10] / print serial [5: -1]
Get home directory with python
Get keyboard events with python
IfcOpenShell python bindings get started
(Python) Get AWS billing amount
Python --bitflyer Get chat content
Get index of nth largest / smallest value in list in Python
Get Alembic information with Python
Get Japanese synonyms in Python
[Python] Execution time when a function is entered in a dictionary value
[Python] How to get a value with a key other than value with Enum
Get Leap Motion data in Python.
Notes on Python and dictionary types
Get started with Python! ~ ① Environment construction ~
[Python] Find the second smallest value.
Link to get started with python
Expansion by argument of python dictionary