dict.get() 函数
dict.get()
函数返回字典中指定键的值,如果键不存在,则返回默认值。
函数类型签名
(default: A, dict: [B:A], key: B) => A where B: Comparable
更多信息,请参阅 函数类型签名。
参数
dict
(必需) 从中返回值的字典。
key
(必需) 从字典返回的键。
default
(必需) 如果键在字典中不存在,则返回的默认值。必须与字典中的值类型相同。
示例
返回字典的属性
import "dict"
d = [1: "foo", 2: "bar"]
dict.get(dict: d, key: 1, default: "")// Returns "foo"
此页是否对您有帮助?
感谢您的反馈!