(a==b) ? 'Yes' : 'No'

Joaquin Abian gatoygata2 at gmail.com
Wed Mar 31 21:11:18 CEST 2010

On Mar 31, 1:18 am, Lawrence D'Oliveiro <l... at geek-
central.gen.new_zealand> wrote:
> In message <7316f3d2-bcc9-4a1a-8598-
> cdd5d41fd... at k17g2000yqb.googlegroups.com>, Joaquin Abian wrote:
> > (a==b) and 'YES' or 'NO'
> > Yes, ugly
> Why would you say that’s ugly?
> By the way, you don’t need the parentheses.

maybe it was not the perfect adjective. I meant 'not beautiful'
because for me it is not an expression I can easily read. It is not
internalized in my brain. I know how to use it because I learnt how to
do it time ago(in Learning Python) but always I have to think how it
works (like a mental translation). For me the other alternative
expresion is more readable:

take_it if you_have_it else search_for_it

this was already in my brain before I started writing python code.
Thus, I prefer this option for my code. On the other hand, in my post,
I proposed the and/or style because I found interesting how
symmetrical it was with the one the OP was refering:

(a==b)  ?  'Yes'  : 'No'
(a==b) and 'Yes' or 'No'

I know, I could write it without parenthesis but it seems more
naturally organized with it and I read it faster and clearly. I dont
know exactly why but it seems also safer to me.


More information about the Python-list mailing list