python – 教授使用“函数的二进制版本”.这甚至存在吗?

python – 教授使用“函数的二进制版本”.这甚至存在吗?,第1张

概述我们的教授在作业中使用了这个.在Google中搜索它后,我不认为“函数的二进制版本”存在.你觉得这意味着什么? Say we have a function add that adds a bunch of numbers. Rather than writing add(3, 5, 4, 1) we want to use currying to create an adder function 我们的教授在作业中使用了这个.在Google中搜索它后,我不认为“函数的二进制版本”存在.你觉得这意味着什么?

Say we have a function add that adds a bunch of numbers. Rather than
writing add(3,5,4,1) we want to use currying to create an adder
function that can be extended using a chain of calls. We would then
have adder(3)(5)(4)(1)(). Let us assume we have the currying function
that can create this adder given the add2 function (the binary version
of add) and a start value. Let us call it curry. Then we have adder =
curry(add2,0).

解决方法 在这种情况下,“binary function”引用一个接受两个参数的参数.在这种情况下,你的教授可能指的是这样的事情:

def add2(x,y):    return x + y    # equivalently: add2 = lambda x,y: x+ydef curry(func,num):    def wrapped(*args):        if len(args) == 0:            return num        elif len(args) > 1:            raise TypeError('{} takes 1 positional argument but '                            '{} were given'.format(                                func.__name__,len(args)))        arg = args[0]        return curry(func,func(num,arg))    return wrapped
总结

以上是内存溢出为你收集整理的python – 教授使用“函数的二进制版本”.这甚至存在吗?全部内容,希望文章能够帮你解决python – 教授使用“函数的二进制版本”.这甚至存在吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1194165.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存