Skip to content

Instantly share code, notes, and snippets.

@ssh0
Created February 15, 2015 16:23
Show Gist options
  • Save ssh0/0a5fc8a7a0429c91c229 to your computer and use it in GitHub Desktop.
Save ssh0/0a5fc8a7a0429c91c229 to your computer and use it in GitHub Desktop.
boolean and "A" or "B"みたいな書き方できたら賢そう【Python】【でも】 ref: http://qiita.com/ssh0/items/51aacabde077c50c0922
>>> def test(flag=True):
... print 'flag: %s' % (flag and 'on' or 'off')
...
>>> test(True)
flag: on
>>> test(False)
flag: off
>>> def test(flag=True):
... print 'flag: %s' % ('on' if flag else 'off')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment