问题描述
例如:
$ b在Python文档中,函数的圆括号内的方括号是什么意思? $ b
( [/ b>] )
或
( [ x [, base ]] ) h2_lin>解决方案
例如:
( [/ b>] )
或
( [ x [, base ]] ) h2_lin>解决方案
方括号内的所有内容都是可选的,即可以忽略它。如果方括号中包含1个以上的参数,则不能选择省略哪些参数,您必须指定所有参数,否则不指定。
这就是嵌套括号派上用场的地方:
int( [ x [, base 例如,您可以使用int()
(
$ b>
>通过忽略整个外括号(或省略整个外括号)或
int(x)
(通过省略内括号)或int(x,base) / code>。但不是
int(base)
(好吧,那就意味着int(x)
)。
这不是实际的Python语法,只是文档更清晰的一种方式。 Python 3的文档试图避免这些括号。
What is the meaning of the square brackets inside the round brackets of a function in the Python documentation?
E.g.:
help([object])
or
int([x[, base]])
解决方案Everything that is in square brackets is optional, i.e. you can omit it. If the square brackets contain more than 1 argument, you can't choose which ones to omit, you must either specify all of them, or none.
That's where nested brackets come in handy:int([x[, base]])Here, for example, you can use
int()
without arguments (by omitting the whole outer bracket) orint(x)
(by omitting the inner bracket) orint(x, base)
. But notint(base)
(well, that would just meanint(x)
).This isn't actual Python syntax, just a way for documentation to be clearer. Python 3's documentation tries to avoid these brackets.
这篇关于int([x [,base]])。 Python文档中函数的方括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!