Python 中dict字典get方法讲解
2017-10-23 22:43
573 查看
Python 中dict字典get方法讲解
python中字典的get方法比较简单,我们看一段代码:x={'a':1,'b':2,'c':3} print(x.get('a',6)) print(x.get(6,'a')) print(x.get(1,6)) print(x.get(2,'a')) print(x.get(6)) print(x.get('a'))
1
a
6
a
None
1
从上面可以看出,python中字典的get方法,其中有两个参数,表示如果第一个值是字典的键,那么返回该键对应的值,如果该值不是字典的键,那么返回第二个值,如果只有第一个值时,表示取该键对应的值,如果该键不存在则返回None
相关文章推荐
- Python字典get()方法的实际应用
- python 字典(dict)get方法应用
- Python 字典 get() 方法
- python字典结构get()方法的陷阱
- Python 字典(Dictionary) get()方法
- Python中字典的get()方法以及defaultdict
- python 字典 get()方法
- Python3 字典 get() 方法
- Python 字典的get()方法
- python 字典 get方法
- Python 字典(Dictionary) get()方法
- 【python】Python的字典get方法:从字典中获取一个值
- python 字典的get方法
- python 字典get方法
- Python语言学习讲解十四:python之用纯属性取代get和set方法
- Python中字典的增、删、创建、索引与字典方法clear,copy,formkeys,get,has_key,popitem,update
- Python 字典(Dictionary) get()方法
- python字典(dictionary)中get和items、iteritems方法
- Python 字典(Dictionary) get()方法
- python 字典 get方法