7
*
在以下代碼中有何含義?(可在pprint
庫中找到)?星號*在函數聲明中的含義是什麼?
def pformat(object, indent=1, width=80, depth=None, *, compact=False):
"""Format a Python object into a pretty-printed representation."""
return PrettyPrinter(indent=indent, width=width, depth=depth,
compact=compact).pformat(object)
如果是*args
那麼它將是任意數量的位置參數。參數值將位於名爲args
的元組中。前4個參數可以按名稱或位置分配,參數compact
只能按名稱分配...
嗯,不!因爲它不與the documentation同意:
在一個函數調用,關鍵字參數必須跟隨位置 參數。
那麼,明星在其他命名參數之後做什麼?那是如何使用的?或者爲什麼它沒有被使用?
謝謝。在提到Python 2文檔頁面的問題中,引用的短語也在3中。 – stenci