less than 1 minute read

Effective Python Item 21: Enforce Clarity with Keyword-Only ArgumentsPEP 3102 – Keyword-Only Arguments

语法 foo(a, b, *, x, y) 可以强制你给 xy 传参数时必须传 keyword arguments,i.e. 必须是 foo(1, 2, x=3, y=4) 而不能是 foo(1, 2, 3, 4)。The * symbol in the argument list indicates the end of positional arguments and the beginning of keyword-only arguments.

Categories:

Updated:

Comments