On 2021-05-24, Alan Gauld via Python-list <python-list@python.org> wrote:
> On 24/05/2021 19:48, Grant Edwards wrote:
>
>>> Traceback (  File "<interactive input>", line 1
>>>     if = 1.234
>>>        ^
>>> SyntaxError: invalid syntax
>> 
>> I must admit it might be nice if the compiler told you _why_ the
>> syntax is invalid (e.g. "expected conditional expression while parsing
>> 'if' statement").
>
> Although wouldn't it be "expected boolean expression" rather than
> conditional expression? Python doesn't care how the argument  to 'if'
> is arrived at so long as it's a boolean.

Indeed -- after posting that I realized that "conditional expression"
was not the best phrase to choose because that's often used to refer
to an expression involving the new ternary operator. I should have
said "boolean valued expression".  Though in the syntax for the
ternary operator expression I've seen such a boolean valued expression
called a "conditional expression".

https://realpython.com/python-conditional-statements/

   <expr1> if <conditional_expr> else <expr2>


-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to