Tuesday, May 14, 2013

python set a variable conditional on another variable

Tiny python snippet. If you're doing this:
if value:
  output = value
else:
  output = 'somethingelse'
Do this instead:
output = value or 'somethingelse'

No comments: