3 ms·
same goes with python - def foo(x=None, y=None): ... foo(x=1, y=2) foo(1, y=2) foo(1, 2)
by wildlogic 7y ago
same goes with python -
def foo(x=None, y=None):
...
foo(x=1, y=2)
foo(1, y=2)
foo(1, 2)
- DonaldPShimoda 7y agoYou can also disable positional handling via * to require keywords in function calls, e.g.: def add(*, l, r): return l + r add(l=1, r=2) >>> 3 add(1, r=2) >>> [...] >>> TypeError: add() takes 0 positional arguments but 1 positional argument (and 1 keyword-only argument) were given I believe 3.8 is adding / (I think) to do the same but for positional arguments, i.e., arguments you cannot give by keyword.
- echelon 7y agoJust be careful not to use mutable objects as your default args.