Re: The ternaery operator

2017-03-16 Thread Gregory Ewing
Stefan Ram wrote: A postponed »if« can be found (x if a, otherwise y), but a preceding »if« (if a, x, otherwise y) also is found often. Yes, both forms occur in English. The point is that Guido didn't just make the idea up, it was inspired by natural language. -- Greg --

Re: The ternaery operator

2017-03-16 Thread Chris Angelico
On Fri, Mar 17, 2017 at 10:45 AM, Stefan Ram wrote: > Gregory Ewing writes: >>wear(red_shirt if it_is_tuesday else green_shirt) > > Operators in Python usually are written with special > symbols, not with words, so a word usually

Re: The ternaery operator

2017-03-16 Thread Gregory Ewing
Tobiah wrote: To be fair, the proper comparison would be: If it's Tuesday, I wear my red shirt, else my green one. The Python analog of that would be if it_is_tuesday: wear(red_shirt) else: wear(green_shirt) i.e. a statement rather than an expression. We're

Re: The ternaery operator

2017-03-16 Thread Jussi Piitulainen
William Mayor writes: >> I think it would be nice to have a way of getting the 'true' value as >> the return with an optional value if false. The desire comes about >> when the thing I'm comparing is an element of a collection: >> >>drugs['choice'] if drugs['choice'] else 'pot' >> >>

Re: The ternaery operator

2017-03-16 Thread alister
On Thu, 16 Mar 2017 03:12:32 +, Stefan Ram wrote: > The syntax > > a if c else b > > looks as if Guido made it intentionally ugly so that it will not be > used? > > Being able to detect patterns that are in widespread use among > programming languages enhances readability. > >

Re: The ternaery operator

2017-03-16 Thread William Mayor
> > I think it would be nice to have a way of getting the 'true' > value as the return with an optional value if false. The desire > comes about when the thing I'm comparing is an element of a collection: > >drugs['choice'] if drugs['choice'] else 'pot' > > Then I'm tempted to do: > >

Re: The ternaery operator

2017-03-16 Thread Tobiah
On 03/16/2017 01:12 AM, Gregory Ewing wrote: > Stefan Ram wrote: > >> a if c else b >> >> Guido has invented something totally new. Why? > > It's arguably closer to the way you would say such a > thing in English. > > Consider the following sentences: > > "I wear my red shirt if it's

Re: The ternaery operator

2017-03-16 Thread Tobiah
On 03/16/2017 01:12 AM, Gregory Ewing wrote: > Stefan Ram wrote: > >> a if c else b >> >> Guido has invented something totally new. Why? > > It's arguably closer to the way you would say such a > thing in English. > > Consider the following sentences: > > "I wear my red shirt if it's

Re: The ternaery operator

2017-03-16 Thread Gregory Ewing
Stefan Ram wrote: a if c else b Guido has invented something totally new. Why? It's arguably closer to the way you would say such a thing in English. Consider the following sentences: "I wear my red shirt if it's Tuesday, else my green one." "I wear if it's Tuesday my red shirt, else my

Re: The ternaery operator

2017-03-16 Thread Christian Gollwitzer
Am 16.03.17 um 04:12 schrieb Stefan Ram: The syntax a if c else b looks as if Guido made it intentionally ugly so that it will not be used? [...] . But now Guido has invented something totally new. Why? The rationale can be read in PEP 308: