为什么Python函数文档在可选参数的括号后面包含逗号? [英] Why do Python function docs include the comma after the bracket for optional args?
问题描述
它们是如何:
RegexObject.match(string [,pos [,endpos]]
以下内容:
RegexObject.match(string,[pos],[endpos])
RegexObject.match [,pos] [,endpos])
括号表示内容是可选的,但方括号之外的所有内容都是强制性的。
使用您的符号:
RegexObject.match(string,[pos],[endpos])
我希望写:
r.match(foo,,)
嵌套是必需的,因为如果提供第三个参数,那么您也必须提供第二个参数,即使它是可选参数。以下非嵌套替代方案将是不明确的:
RegexObject.match(string [,pos] [,endpos])
The format of the function signatures in the Python docs is a bit confusing. What is the significance in putting the comma after the open bracket, rather than before? What is the significance of nesting the brackets?
How they are:
RegexObject.match(string[, pos[, endpos]])
I would expect one of the following:
RegexObject.match(string, [pos], [endpos])
RegexObject.match(string[, pos][, endpos])
The square bracket means that the contents are optional, but everything outside of square brackets is compulsory.
With your notation:
RegexObject.match(string, [pos], [endpos])
I would expect to have to write:
r.match("foo",,)
The nesting is required because if you supply the third parameter then you must also supply the second parameter even though it is an optional parameter. The following non-nested alternative would be ambiguous:
RegexObject.match(string[, pos][, endpos])
这篇关于为什么Python函数文档在可选参数的括号后面包含逗号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!