Positional-only parameters for Python
Positional-only parameters for Python
Posted Apr 10, 2019 16:35 UTC (Wed) by dbaker (guest, #89236)In reply to: Positional-only parameters for Python by FLHerne
Parent article: Positional-only parameters for Python
not only that, _ is the conventional name of any variables that you're going to ignore. Which is really handy for a lot of things;
iterating over containers of containers:
for a, b, _ in [(1, 'a', []), (2, 'b', [])]: ...
for functions that need to fulfill an interface:
def f1(f: str, *, opt: bool = False):
def f2(f: str, **_):
myval = [f(myval, opt=True) for f in [f1, f2]]
with the python3 partial container explosion syntax:
a, b, *_ = (1, 2, 3, 4)
and a bunch of other cases.
