是否有可能在不创建临时变量且不使用if语句的情况下实现与下面的代码相同的结果?我尝试了很多东西,但我对python很新.
def get_value(dictionary, key):
temp = dictionary.get(key)
if temp = None:
return "Sorry this item doesn't exist"
else:
return temp
Run Code Online (Sandbox Code Playgroud)
即我正在努力实现的目标
def get_value(dictionary, key):
return dictionary.get(key) else return "Sorry this item doesn't exist"
Run Code Online (Sandbox Code Playgroud)