5 ms·
This is wild and something I didn't know about: https://blog.edward-li.com/tech/advanced-python-features/#2-keyword-only-and-positional-only-arguments https://
by djoldman 2y ago
This is wild and something I didn't know about:
https://blog.edward-li.com/tech/advanced-python-features/#2-keyword-only-and-positional-only-arguments https://blog.edward-li.com/tech/advanced-python-features/#2-...
def bar(a, /, b):
...
# == ALLOWED ==
bar(1, 2) # All positional
bar(1, b=2) # Half positional, half keyword
# == NOT ALLOWED ==
bar(a=1, b=2) # Cannot use keyword for positional-only parameter
- zahlman 2y agoReference: https://peps.python.org/pep-0570/ https://peps.python.org/pep-0570/
- lordgrenville 2y agoAnd you can use * for the reverse (every parameter from here on needs to be keyword-only). https://docs.python.org/3.12/reference/compound_stmts.html#function-definitions https://docs.python.org/3.12/reference/compound_stmts.html#f...
- mckirk 2y agoThat feature I'm using regularly and can recommend doing so, e.g. when passing boolean flags to functions, to clarify their meaning at the call-site by ensuring they have to be passed by name.