Python3 字典 get() 方法
2018-03-29 15:24
429 查看
描述
Python 字典 get() 函数返回指定键的值,如果值不在字典中返回默认值。语法
get()方法语法:dict.get(key, default=None)参数
key -- 字典中要查找的键。default -- 如果指定键的值不存在时,返回该默认值值。
返回值
返回指定键的值,如果值不在字典中返回默认值 None。实例
以下实例展示了 get()函数的使用方法:#!/usr/bin/python3dict = {'Name': 'Runoob', 'Age': 27}
print ("Age 值为 : %s" % dict.get('Age'))
print ("Sex 值为 : %s" % dict.get('Sex', "NA"))以上实例输出结果为:Age 值为 : 27
Sex 值为 : NA
相关文章推荐
- python 字典(dict)get方法应用
- Python 字典的 get() 方法和 [key] 方法对比
- python 字典的get方法
- Python中字典的增、删、创建、索引与字典方法clear,copy,formkeys,get,has_key,popitem,update
- Python 字典(Dictionary) get()方法
- Python 字典(Dictionary) get()方法
- python 字典 get方法
- Python 字典(Dictionary) get()方法
- Python 字典(Dictionary) get()方法
- Python中字典get方法的使用
- Python 字典(Dictionary) get()方法
- python字典(dict)get方法
- python 字典 get(),items(),iteritems()方法
- python字典get()方法用法分析
- python 字典(dict)get方法应用
- python-字典get方法
- python字典结构get()方法的陷阱
- Python 中dict字典get方法讲解
- Python 字典(Dictionary) get()方法
- 【python】Python的字典get方法:从字典中获取一个值