最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

自定義函數(shù)的調(diào)用,解釋一下reduce()中的第一個(gè)參數(shù)

自定義函數(shù)的調(diào)用,解釋一下reduce()中的第一個(gè)參數(shù)

zhang_lei 2016-03-22 17:44:18
def?calc_prod(lst): ????def?prod(): ????????return?reduce(lambda?x,?y?:?x?*?y,?lst) ????return?prod f?=?calc_prod([1,?2,?3,?4]) print?f()
查看完整描述

1 回答

已采納
?
清波

TA貢獻(xiàn)165條經(jīng)驗(yàn) 獲得超90個(gè)贊

官方解釋如下:


? ? reduce(...)

? ? ? ? reduce(function, sequence[, initial]) -> value

? ? ? ??

? ? ? ? Apply a function of two arguments cumulatively to the items of a sequence,

? ? ? ? from left to right, so as to reduce the sequence to a single value.

? ? ? ? For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates

? ? ? ? ((((1+2)+3)+4)+5). ?If initial is present, it is placed before the items

? ? ? ? of the sequence in the calculation, and serves as a default when the

? ? ? ? sequence is empty.

大致意思是,放入兩個(gè)參數(shù),一個(gè)是function, 另外一個(gè)是 可迭代對(duì)象,然后會(huì)返回用function 代入 可迭代對(duì)象后 的值。 類似官方解釋中的案例:

reduce(lambda?x,?y:?x+y,?[1,?2,?3,?4,?5])?
##?結(jié)果為?:?((((1+2)+3)+4)+5).
即:?sum([1,2,3,4,5]),?列表各項(xiàng)的和


查看完整回答
反對(duì) 回復(fù) 2016-03-23
  • 1 回答
  • 0 關(guān)注
  • 1742 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)