Python3 字典 get() 方法
Python 3 教程
· 2019-02-06 15:43:05
描述
Python 字典 get() 函数返回指定键的值,如果值不在字典中返回默认值。
语法
get()方法语法:
dict.get(key, default=None)
参数
- key -- 字典中要查找的键。
- default -- 如果指定键的值不存在时,返回该默认值值。
返回值
返回指定键的值,如果值不在字典中返回默认值 None。
实例
以下实例展示了 get()函数的使用方法:
#!/usr/bin/python3
dict = {'Name': 'Codercto', 'Age': 27}
print ("Age 值为 : %s" % dict.get('Age'))
print ("Sex 值为 : %s" % dict.get('Sex', "NA"))
以上实例输出结果为:
Age 值为 : 27 Sex 值为 : NA
点击查看所有 Python 3 教程 文章: https://www.codercto.com/courses/l/10.html
Paradigms of Artificial Intelligence Programming
Peter Norvig / Morgan Kaufmann / 1991-10-01 / USD 77.95
Paradigms of AI Programming is the first text to teach advanced Common Lisp techniques in the context of building major AI systems. By reconstructing authentic, complex AI programs using state-of-the-......一起来看看 《Paradigms of Artificial Intelligence Programming》 这本书的介绍吧!