python

python中get函数怎么用

九三
519
2021-01-28 13:36:45
栏目: 编程语言

python中get函数怎么用

在python中使用get函数的方法

get:get()函数的作用是返回指定键的值。

get()函数语法:

dict.get(key, default=None)

参数:

key:字典中要查找的键。

default:如果指定键的值不存在时,返回该默认值。

get()函数使用方法:

dict = {'Name': 'Runoob', 'Age': 27}

print "Value : %s" % dict.get('Age')

print "Value : %s" % dict.get('Sex', "Never")

输出结果为:

Value : 27

Value : Never

0
看了该问题的人还看了