Modern Programming
Modern Programming


Modern Programming
You're viewing a single thread.
I love something = condition and result1 or result2
in lua
Python does that, too.
https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not
Are you just referring to how Python uses the English and
/or
instead of the more common &&
/||
? I think what the user above you was talking about was Lua's strange ternary syntax using and
/or
.
no, the linked table shows how python also returns the first non-falsey result of an a or b
expression rather than just giving a boolean. it's useful for initialising optional reference args:
undefined
def foo(a: list = None) a = a or []
works with and
as well.
often I do a function called elvis XD with the next signature elvis(condition, res1, res2)