第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

def calc_prod(lst): def lazy_prod(): def f(x, y): return x * y return reduce(f, lst, 1) return lazy_prod f = calc_prod([1, 2, 3, 4]) print (f()) Traceback (most recent call last): File "<ipython-input-28-5166a7a3086

def calc_prod(lst):

? ? def lazy_prod():

? ? ? ? def f(x, y):

? ? ? ? ? ? return x * y

? ? ? ? return reduce(f, lst, 1)

? ? return lazy_prod


f = calc_prod([1, 2, 3, 4])

print (f())

Traceback (most recent call last):


? File "<ipython-input-28-5166a7a30861>", line 9, in <module>

? ? print (f())


? File "<ipython-input-28-5166a7a30861>", line 5, in lazy_prod

? ? return reduce(f, lst, 1)


NameError: name 'reduce' is not defined


正在回答

1 回答

你用的是python2的語(yǔ)法,但是你的環(huán)境是python3的環(huán)境。reduce函數(shù)在python3的內(nèi)建函數(shù)移除了,放入了functools模塊??梢栽谇懊嫣砑舆@樣一行代碼:

from?functools?import?reduce


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
python進(jìn)階
  • 參與學(xué)習(xí)       255552    人
  • 解答問(wèn)題       3038    個(gè)

學(xué)習(xí)函數(shù)式、模塊和面向?qū)ο缶幊?,掌握Python高級(jí)程序設(shè)計(jì)

進(jìn)入課程

def calc_prod(lst): def lazy_prod(): def f(x, y): return x * y return reduce(f, lst, 1) return lazy_prod f = calc_prod([1, 2, 3, 4]) print (f()) Traceback (most recent call last): File "<ipython-input-28-5166a7a3086

我要回答 關(guān)注問(wèn)題
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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