2 ms·
return x is way more pythonic, because it's much clearer and any non-boolean value can be used in boolean contexts as well.
by cool_guy_this 10y ago
return x is way more pythonic, because it's much clearer and any non-boolean value can be used in boolean contexts as well.
- coldtea 10y agoYou can also "return not not x" which turns the value into its boolean true/false equivalent ("!!x" in a C-like language). Or "return bool(x)" to make this more explicit. Those would be handy e.g. if the code that uses your result behaves differently 0 and False.