我想知道在字典中是否有一种方式可以设置默认值(而不使用get函数),使得:
dict colors = {
"Black":(0, 0, 0),
"White":(255, 255, 255),
default:(100, 100, 100)
};
paint(colors["Blue"]); # Paints the default value (Grey) onto the screen
当然,上述代码在Python中无法运行,我严重怀疑这是不可能的。
我知道通过使用“get”函数可以轻松实现此操作,但我仍然好奇是否有其他方法(只是出于好奇)。