Python Conditional Expressions
Written by Ben on September 19, 2006 |
Python had lacked a C equivalent of the “condition ? true_value : false_value” expression. So we used a work around until now… conditional expressions finally made it in to Python’s 2.5 release.
In Python2.4:
x = ((condition) and true_value) or false_value
In Python2.5:
x = true_value if condition else false_value
Yeah, the statement looks better in Python2.5.
Posted in Python
![[del.icio.us]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/digg.png)
![[Google]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/google.png)
![[StumbleUpon]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Windows Live]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/email.png)
Uh … is this related to SoAP? I can’t tell. It’s late, and I’m catching a plane for NZ in a few hours. I just thought I’d check in and see what you’ve been up to. Saw you left Europe early and wondered whether it was something we said …. And what you’re getting up to back in the good ‘ol US of A — besides general geekiness. Adjusting alright? Drop me a line! And wish me luck for NZ : / I need sleep.
Cheers–
Brie
Comment by Brie — October 2, 2006 @ 4:09 pm
I just stumbled upon this googling for conditionals in python. The a and b or c is smart, but it wont work for false b obviously… I hope your code didnt have bugs due to this
Comment by saurabh — April 15, 2008 @ 2:03 pm