There is a code example in the O Reilly Programming Python book which uses an OR operator in a lambda function. The text states that "[the code] uses an or operator to force two expressions to be run".
How and why does this work?
widget = Button(None, # but contains just an expression
text='Hello event world',
command=(lambda: print('Hello lambda world') or sys.exit()) )
widget.pack()
widget.mainloop()
解决方案
Every funnction in Python returns a value. If there is no explicit return statement it returns None. None as boolean expression evaluates to False. Thus, print returns None, and the right hand side of the or expression is always evaluated.