Python syntax error when I use if on same line -
i must doing stupid don't see it. not following simple code work.
>>> def a_bigger_than_b(a,b): ... 'yes' if > b file "<stdin>", line 2 'yes' if > b ^ syntaxerror: invalid syntax
def a_bigger_than_b(a,b): ... return 'yes' if > b else 'no!'
actually using ternary operator
in such case need else
i think must give else can understood by
first
c='yes' if > b
what value if smaller b case ambiguous else must
correct syntax
c='yes' if > b else 'no!'
a detailed explanation given here
*on 9/29/2005, guido decided add conditional expressions in form of "x if c else y". motivating use case prevalance of error-prone attempts achieve same effect using "and" , "or". previous community efforts add conditional expression stymied lack of consensus on best syntax. issue resolved deferring bdfl best judgment call.*
Comments
Post a Comment