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