标签:
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法get() #http://www.runoob.com/python/att-dictionary-get.html #dict.get(key, default=None) #说明:返回指定键的值,如果值不在字典中返回默认值. #key:要查找的键 #default:如果指定键的值不存在时,返回该默认值值 ‘‘‘ >>> help(d.get) Help on built-in function get: get(...) D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None. 如k在D中,返回 D[K] 否则,返回defaults ‘‘‘ #案例 d={‘name‘:‘xiaodeng‘,‘age‘:28} print d.get(‘name‘,‘red‘) #xiaodeng print d.get(‘color‘,‘red‘) #red print d #{‘age‘: 28, ‘name‘: ‘xiaodeng‘}
标签:
原文地址:http://www.cnblogs.com/dengyg200891/p/4946315.html