我正经历string.Template
,并注意到该方法的参数中有一个斜杠。
Python版本: 3.8.0
def substitute(self, mapping=_sentinel_dict, /, **kws):
if mapping is _sentinel_dict:
mapping = kws
elif kws:
mapping = _ChainMap(kws, mapping)
我创建了一个小功能来对此进行测试。
def s(a=1, /):
print(a)
s(3) # Outputs 3
s(2, 3) # TypeError: s() takes from 0 to 1 positional arguments but 2 were given