Little bit of Python Zen - ternary

home | blog | Teh Internet | guest blog |rants | placeholder | political | projects | Gwen and Liam | Citadel patched | Tools | Scouts


- Careful Chrome users, this search box might be "Not secure"



Looks nice:
 z = a if a > b else b

Came across it here:
http://pysnippet.blogspot.com/2010/03/ternary-operation.html

Compare to PHP
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];

Looks like the Ruby folks learned syntax from either PHP or Sinclair
no intended slam on Sinclair Research, as they used the ? to a great
end in that it was such a help in line edits in their basic
a feat that has still not been accomplished in either VI or EMACS!

Sorry for the rant, here is the Ruby pseudo-code
test-expression ? if-true-expression : if-false-expression


Which one reads faster?




[æ]