raise statement on a conditional expression
问题 Following "Samurai principle", I'm trying to do this on my functions but seems it's wrong... return <value> if <bool> else raise <exception> Is there any other "beautiful" way to do this? Thanks 回答1: Inline/ternary if is an expression, not a statement. Your attempt means "if bool, return value, else return the result of raise expression " - which is nonsense of course, because raise exception is itself a statement not an expression. There's no way to do this inline, and you shouldn't want to.