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
To print a value in Python, you call the print() function. Returning is used to return a value from a function and exit the function. To return a value from a function, use the return keyword.
A return statement is used to end the execution of the function call and “returns” the result (value of the expression following the return keyword) to the caller. The statements after the return statements are not executed. If the return statement is without any expression, then the special value None is returned.
If a function doesn't specify a return value, it returns None . In an if/then conditional statement, None evaluates to False.
Easy peasy:
'String ok' if value == 'ok' else 'String nok'
It's a conditional expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With