示例示例Python字典get()方法用于获取指定键的值,如果键不存在,则返回None。语法:
Python字典get()方法用于获取指定键的值,如果键不存在,则返回None。
语法:
dict.get(key, default=None)
参数:
key -- 字典中要查找的键。
default -- 如果指定键的值不存在时,返回该默认值值。
示例:
dict = {'Name': 'Runoob', 'Age': 7, 'Cl': 'First'}
print("dict['Name']: ", dict.get('Name'))
print("dict['Age']: ", dict.get('Age'))
print("dict['Alice']: ", dict.get('Alice'))
输出结果:
dict['Name']: Runoob
dict['Age']: 7
dict['Alice']: None
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(34条)