int([x [,base]])。 Python文档中函数的方括号? [英] int([x[, base]]). Square brackets in functions in Python documentation?

查看:496
本文介绍了int([x [,base]])。 Python文档中函数的方括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如:


$ b在Python文档中,函数的圆括号内的方括号是什么意思? $ b

帮助 [/ b>]





int [ x [ base ]] h2_lin>解决方案

方括号内的所有内容都是可选的,即可以忽略它。如果方括号中包含1个以上的参数,则不能选择省略哪些参数,您必须指定所有参数,否则不指定。

这就是嵌套括号派上用场的地方:


$ b $

 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) or int(x) (by omitting the inner bracket) or int(x, base). But not int(base) (well, that would just mean int(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文档中函数的方括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆