Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
int在Python 2中接受x作为关键字参数_Python_Python 2.7_Python 3.6 - Fatal编程技术网

int在Python 2中接受x作为关键字参数

int在Python 2中接受x作为关键字参数,python,python-2.7,python-3.6,Python,Python 2.7,Python 3.6,以下内容在Python 2.7中使用: In [79]: int(x=5) Out[79]: 5 In [31]: int(x=5) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-31-53a6d75bf

以下内容在Python 2.7中使用:

In [79]: int(x=5)
Out[79]: 5
In [31]: int(x=5)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-31-53a6d75bfa9f> in <module>
----> 1 int(x=5)

TypeError: 'x' is an invalid keyword argument for int()
。。但在Python 3.6中失败:

In [79]: int(x=5)
Out[79]: 5
In [31]: int(x=5)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-31-53a6d75bfa9f> in <module>
----> 1 int(x=5)

TypeError: 'x' is an invalid keyword argument for int()
[31]中的
int(x=5)
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在里面
---->1整数(x=5)
TypeError:“x”是int()的无效关键字参数

似乎在python3中已更正该行为,不接受
x
作为关键字参数。有人能确认我的理解是正确的,或者纠正我吗?谢谢。

根据Python2文档:

整数签名是
class int(x=0)
class int(x,base=10)
,它支持在`int(x=5)情况下观察到的赋值

根据Python3文档:


int签名是
class int([x])
class int(x,base=10)
,其中x是在函数参数外赋值的变量,如
int('5')
,根据Python2文档:

整数签名是
class int(x=0)
class int(x,base=10)
,它支持在`int(x=5)情况下观察到的赋值

根据Python3文档:


int签名是
class int([x])
class int(x,base=10)
其中x是在函数参数外部赋值的变量,如
int('5')
在Python 2中,
int()
的签名是

int(x=0)
int(x, base=10)
在Python 3中,它几乎是相同的:

int([x])
int(x, base=10)

但在Python2中,不可能禁止关键字参数。在Python3中是。

在Python2中,
int()的签名是

int(x=0)
int(x, base=10)
在Python 3中,它几乎是相同的:

int([x])
int(x, base=10)

但在Python2中,不可能禁止关键字参数。在Python 3中是这样的。

是的,签名已更改。你可以比较这些文件

显示此签名

class int([x])
class int(x, base=10)
但这表明:

class int(x=0)
class int(x, base=10)

请注意,
3.x
不接受关键字参数,而
2.x
接受关键字参数。

是的,签名已更改。你可以比较这些文件

显示此签名

class int([x])
class int(x, base=10)
但这表明:

class int(x=0)
class int(x, base=10)

注意
3.x
不接受关键字参数,而
2.x
接受关键字参数。

在pythong 3.6中,应该用逗号分隔。 int()方法的语法是:int(x=0,base=10)


您可以在这里的文档中看到更多信息:

在pythong 3.6中,您应该用逗号分隔。 int()方法的语法是:int(x=0,base=10)


您可以在这里的文档中看到更多信息:

int
在python 3中只需要两个非关键字参数,即字符串和基。根据,它在python 3.7+中应该只会失败(“
在版本3.7中更改:x现在是一个位置参数。
”)。我用Python3.6.1对它进行了测试,它没有抛出错误。但这可能是ipython安装的实现细节。
int
在Python3中只需要两个非关键字参数,即字符串和based。根据,它在Python3.7+中应该只会失败(“
在3.7:x版本中更改后现在是一个位置参数。
”)。我用Python3.6.1对它进行了测试,它没有抛出错误。但这可能是ipython安装的实现细节。