@ 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