Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.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
Python 如何将元组作为参数传递给'divmod()`函数_Python_Python 3.x - Fatal编程技术网

Python 如何将元组作为参数传递给'divmod()`函数

Python 如何将元组作为参数传递给'divmod()`函数,python,python-3.x,Python,Python 3.x,我一直在尝试,但失败了很多次: >>> x = (21, 4) >>> divmod(x) File "<stdin>", line 1, in <module> TypeError: divmod expected 2 arguments, got 1 >x=(21,4) >>>divmod(x) 文件“”,第1行,在 TypeError:divmod需要2个参数,得到1个 这怎么可能呢 据我所知,divmod() 要提供一个元

我一直在尝试,但失败了很多次:

>>> x = (21, 4)
>>> divmod(x)
 File "<stdin>", line 1, in <module>
TypeError: divmod expected 2 arguments, got 1
>x=(21,4)
>>>divmod(x)
文件“”,第1行,在
TypeError:divmod需要2个参数,得到1个
这怎么可能呢

据我所知,
divmod()

要提供一个元组作为
divmod()
函数的参数,必须在元组前面使用*散点

因此,您的代码应该类似于:

>>> x = (21, 4)
>>> divmod(*x)
(5, 1)
所以商是
5
,余数是
1