LoginSignup
0
2

More than 5 years have passed since last update.

Python > dictionary > get() > optional value

Last updated at Posted at 2017-03-08

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

PythonのDictionaryの要素を取り出す関数get()について。

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

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

dictionary "pythons"に含まれていない場合の例。

試してみた。

mydic = {'7of9' : 'borg', 'Chakotay' : 'human', 'Janeway' : 'human'}
print(mydic.get('7of9', 'unknown'))
print(mydic.get('Chakotay', 'unknown'))
print(mydic.get('Tuvok', 'unknown'))
結果
Success time: 0 memory: 23352 signal:0
borg
human
unknown
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2