Pythonic way for `return (value == 'ok') ? 'ok' : 'nok' `
Question:
Possible Duplicate:
Ternary conditional operator in Python
I have this problem and have no idea to ask google for this:
(value == 'ok') ? 'ok' : 'not ok'
I mean that grammar with:
(expression) ? (return if <expresion> is true) : (return this value if <expresion> is false
Answers:
How about this case:
{True: 'String ok', False: 'String nok'}[value == 'ok']
*Do not take seriously 🙂
Possible Duplicate:
Ternary conditional operator in Python
I have this problem and have no idea to ask google for this:
(value == 'ok') ? 'ok' : 'not ok'
I mean that grammar with:
(expression) ? (return if <expresion> is true) : (return this value if <expresion> is false
How about this case:
{True: 'String ok', False: 'String nok'}[value == 'ok']
*Do not take seriously 🙂