wei/unit_6/alien_no_paints.py

9 lines
363 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

alien_0 = {'color': 'green', 'speed': 'slow'}
#当输出一个不存在的键时会报错 KeyError
# print(alien_0['point'])
#可使用get来查找键 第一个参数指定查找内容 第二个参数当指定的键不存在的时候会返回的值可省略默认为none
point_value = alien_0.get('point', 'no point value assigned')
print(point_value)