Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As pointed out in the OP, there are actually quite a lot of ways to simulate the ternary operator in Python. An interesting one is (result, alternative)[test]. If result and alternative are functions you could write it as (result, alternative)[test]().

And for desert: I love this syntax:

  if 0 < x <= 100: pass
For more info see: http://stackoverflow.com/questions/394809/python-ternary-ope...


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: