In [1]:
# https://docs.python.jp/3/library/stdtypes.html#mapping-types-dict

In [2]:
d = {'one': 1, 'two': 2, 'three': 3}

In [3]:
print(d)
print(d.keys())
print(d.values())
print(d.items())


{'one': 1, 'two': 2, 'three': 3}
dict_keys(['one', 'two', 'three'])
dict_values([1, 2, 3])
dict_items([('one', 1), ('two', 2), ('three', 3)])

In [4]:
print(d.get('one'))


1

In [5]:
print(d.get('four'))


None

In [6]:
print(d.get('five', 'default_value'))


default_value

In [7]:
print(d)


{'one': 1, 'two': 2, 'three': 3}

In [8]:
print(d.setdefault('one'))


1

In [9]:
print(d.setdefault('four'))
print(d)


None
{'one': 1, 'two': 2, 'three': 3, 'four': None}

In [10]:
print(d.setdefault('five', 'default_value'))
print(d)


default_value
{'one': 1, 'two': 2, 'three': 3, 'four': None, 'five': 'default_value'}