0
def doblue(): print "The sea is blue"
def dogreen(): print "Grass is green"
def doyellow(): print "Sand is yellow"
def redflag():
print "Red is the colour of fire"
print "do NOT play with fire"
def errhandler():
print "Your input has not been recognised"
设立的行动字典
takeaction = {
"blue": doblue,
"green": dogreen,
"yellow": doyellow,
"red": redflag}
colour = raw_input("Please enter red blue green or yellow ")
takeaction.get(colour,errhandler)()
,如果我有一些参数传递给doblue()或任何这种功能??使用辞典蟒蛇将参数传递给函数在开关的情况下
请使用StackOverflow的代码示例表示法重新编写代码以使其可读。 – Jakob
'takeaction.get(color,errhandler)(parameters)'如果这是你想要的 – The6thSense
谢谢。有效。 –