syntax - Conditional operator in Python? -


Did you know that Python supports backing some keywords or expressions such as C ++ values ​​< If> condition, all in the same line (expressed with C ++ if question mark )

  // C ++ value = (a & gt; 10; b: c)  

< P> Since Python 2.5 you can:

  value = b if a & gt; 10 and C  

Before that you have to do something like the following, although semantics are not equal because the short circuiting effect is lost:

  value = [ C, B] [A & gt; 10]  

There is another hack using 'and ... or' but it is best to use it because in some cases there is an undesirable behavior in which to find the bug There can be difficulty. I will not even write a hack here because I think it's best not to use it, but you can read about it if you want to.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -