日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python函数实例化_用Python实例化函数

發(fā)布時(shí)間:2025/3/11 python 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python函数实例化_用Python实例化函数 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

python函數(shù)實(shí)例化

In terms of Mathematics and Computer science, currying is the approach/technique by which we can break multiple-argument function to single argument function.

從數(shù)學(xué)和計(jì)算機(jī)科學(xué)的角度來看, 柯里化是一種方法/技術(shù),通過它我們可以將多參數(shù)功能分解為單參數(shù)功能。

Mathematical illustration: h(x)=g(f(x))

數(shù)學(xué)圖示:h(x)= g(f(x))

The composition of two functions is a chaining process in which the output becomes the input for the outer function.

兩個(gè)函數(shù)的組合是一個(gè)鏈接過程,其中輸出成為外部函數(shù)的輸入。

def currying( g , f ):def h(x):return g(f(x))return h

In the technical term "Currying is the process of transforming a function that takes 'n' arguments into a series of 'n' function that only takes the one argument each."

在技??術(shù)術(shù)語中, “固化是將采用'n'個(gè)參數(shù)的函數(shù)轉(zhuǎn)換為一系列只采用一個(gè)參數(shù)的'n'函數(shù)的過程。”

In problem-solving approach, currying is to be done to simplify the programming i.e. execution of the function which takes multiple arguments into the single - single argument functions.

在解決問題的方式, 鉆營被做了簡化這需要多個(gè)參數(shù)到單一功能的編程也就是執(zhí)行-單參數(shù)的函數(shù)。

Example code 1:

示例代碼1:

def f(a):def g(b, c, d, e):print(a, b, c, d, e)return g #as in f it return g this is curryingf1 = f(1)f1(2,3,4,5)

Output

輸出量

1 2 3 4 5

Explanation of the above code:

上面的代碼說明:

Now, f(1) returns the function g(b, c, d, e) which, for all b, c, d, and e, behaves exactly like f(1, b, c, d, e). Since g is a function, it should support currying as well.

現(xiàn)在, f(1)返回函數(shù)g(b,c,d,e) ,對(duì)于所有b , c , d和e ,其行為都與f(1,b,c,d,e)完全一樣。 由于g是一個(gè)函數(shù),因此它也應(yīng)該支持curring 。

Example code 2:

示例代碼2:

def f(a):def g(b):def h(c):def i(d):def j(e):print(a, b, c, d, e)return j #return to function ireturn i #return to function hreturn h #return to function greturn g #return to function ff(1)(2)(3)(4)(5)

Output

輸出量

1 2 3 4 5

Explanation of the above code:

上面的代碼說明:

In the code we have, X(a,b,c,d,e) = f(g(h(i(j(a,b,c,d,e))))

在代碼中, X(a,b,c,d,e)= f(g(h(i(j(a,b,c,d,e))))

Here, the concept is of nesting of one function to another and hence the result of one function get stored or recorded in another function as a chain of functions.

在此,概念是將一個(gè)功能嵌套到另一個(gè)功能,因此一個(gè)功能的結(jié)果作為功能鏈存儲(chǔ)或記錄在另一個(gè)功能中。

Note: Now f(a,b,c,d,e) is no more i.e. now f no more take 5 arguments.

注意:現(xiàn)在f(a,b,c,d,e)不再存在,即現(xiàn)在f不再接受5個(gè)參數(shù)。

Python example of currying function to convert INR to pounds

將INR轉(zhuǎn)換為英鎊的currying函數(shù)的Python示例

# program to covert the Indian Rupee to Pound # Demonstrating Currying of composition of function def change(b, c): def a(x): #by currying functionreturn b(c(x)) return a def IR2USD(ammount): return ammount*0.014 # as 1IR=0.014USDdef USD2Pound(ammount): # Function converting USD to Pounds return ammount * 0.77 if __name__ == '__main__': Convert = change(IR2USD,USD2Pound )e = Convert(565)print("Conveted Indian Rupee to Pound:")print('565 INDIAN RUPEES =',e,'PoundSterling')

Output

輸出量

Conveted Indian Rupee to Pound: 565 INDIAN RUPEES = 6.0907 PoundSterling

翻譯自: https://www.includehelp.com/python/currying-function-with-example.aspx

python函數(shù)實(shí)例化

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的python函数实例化_用Python实例化函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。