【发布时间】:2020-12-12 12:39:42
【问题描述】:
我注意到一些带有/ 参数的函数签名。这方面的一个例子可以在collections.Counter.__init__()找到:
def __init__(self, iterable=None, /, **kwds):
'''Create a new, empty Counter object. And if given, count elements
from an input iterable. Or, initialize the count from another mapping
of elements to their counts.
>>> c = Counter() # a new, empty counter
>>> c = Counter('gallahad') # a new counter from an iterable
>>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping
>>> c = Counter(a=4, b=2) # a new counter from keyword args
'''
super().__init__()
self.update(iterable, **kwds)
我无法找到它的用途,当我尝试在本地复制它时,我得到了 SyntaxError。
任何关于它是什么以及为什么使用它的信息都将不胜感激。
【问题讨论】:
标签: python collections