|
发表于 2023-1-11 09:31:07
|
显示全部楼层
本楼为最佳答案
本帖最后由 isdkz 于 2023-1-11 09:33 编辑
你在交互模式执行一下 help(pow),你就知道 pow 的形参的名字,
python 3.7 的 pow 函数的形参名字跟 python 3.11 的 pow 参数的形参名字是不一样的,
而且 python 3.7 的 pow 函数不支持关键字参数,/ 表示 / 前面的参数只能以位置参数的方式传递,
python3.7:
python3.11:
所以没有办法,你的偏函数只能固定第一个参数,而且不能用关键字的方式,
要固定第二个参数就只能你自己实现闭包了
- def closure(y):
- def func(x, *args):
- return pow(x, y, *args)
- return func
- square = closure(2)
- square(2)
- square(4, 5)
- pow(4, 2, 5)
复制代码>>> def closure(y):
... def func(x, *args):
... return pow(x, y, *args)
... return func
...
>>> square = closure(2)
>>> square(2)
4
>>> square(4, 5)
1
>>> pow(4, 2, 5)
1
>>> |
|