每当我输入以下代码时:
def in_fridge():
try:
count =fridge [wanted_food]
except KeyError:
count =0
return count
fridge ={"apples":10, "oranges":3, "milk":9}
wanted_food="apples"
in_fridge()
Run Code Online (Sandbox Code Playgroud)
进入IDLE,输出"10".
当我在代码编辑器中输入相同的代码然后按F5时,不输出任何内容.作为测试,我在代码编辑器中创建了一个新文件,输入:
print ("Hello World")
Run Code Online (Sandbox Code Playgroud)
并尽职尽责地得到了输出的结果,即从IDLE shell在新窗口中显示的hello world.
所以我很好奇为什么我在IDLE环境中显示的值而不是代码编辑器,当我输入完全相同的代码时:(