I am new to python. I have a few questions coming from an armature!

Terry Reedy tjreedy at udel.edu
Wed Aug 17 17:59:31 EDT 2016


On 8/17/2016 2:39 PM, Random832 wrote:
> On Wed, Aug 17, 2016, at 14:27, Terry Reedy wrote:
>> That particular syntax was not really considered.  At least 10 versions
>> using 'if', 'then', 'else', and other tokens were.
>>
>> They all had the problem of requiring a new keyword such as 'then' or
>> some other innovation.
>
> Why not just if(cond, trueval, falseval), a la Visual Basic?
>
> It's too late to change now, but I'm curious as to whether it was
> considered or not.

It is already valid Python, parsed as 'if' 'tuple'

 >>> if(1,2): 3

3

A space after 'if' is not optional if the next char is an identifier 
char, as in 'ifx' as this is parsed as the identifier 'ifx', not 'if' 'x'.

Anyone can define an iff(cond, true_func, false_func) function

def iff(cond, f_true, f_false):
     return (f_true if cond else f_false)()

or a non-short-circuiting iff(cond, true_val, false_val) function, but 
it hardly seems worth the effort.

-- 
Terry Jan Reedy




More information about the Python-list mailing list