Dec-10-2020, 04:13 PM
(This post was last modified: Dec-10-2020, 04:13 PM by deanhystad.)
Quote:return statement can only be used in a function, not elsewhereThis may or may not be a problem here. We have no context provided for the code in question. But this is invalid Python if it is in a function or not. "return" is not an expression. A ternary expression is "expression condition expression". In
answer = 'odd' if x % 2 else 'even''even' and 'odd' are expressions and 'if x % 2 else' is the condition.
An expression is something that evaluates to a value. A string is an expression. An equation is an expression. A function call is an expression. A "return", ironically, is not an expression because it does not evaluate to a value.