您的位置:首页 > 编程语言 > Python开发

[Python] The get() method on Python dicts and its "default" arg

2017-10-01 18:30 579 查看
# The get() method on dicts
# and its "default" argument

name_for_userid = {
382: "Alice",
590: "Bob",
951: "Dilbert",
}

def greeting(userid):
return "Hi %s!" % name_for_userid.get(userid, "there")

>>> greeting(382)
"Hi Alice!"

>>> greeting(333333)
"Hi there!"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐