Discuss / Python / 第二题为什么会出现这个问题?

第二题为什么会出现这个问题?

Topic source

范巴i特

#1 Created at ... [Delete] [Delete and Lock User]

-- coding: utf-8 --

from functools import reduce

def prod(L): def C(a,b): return a*b reduce(C,L)

L=[3,5,7,9] print ('357*9=',prod(L))

为什么函数输出的是None啊,编程小白一枚求教

兔菲絮

#2 Created at ... [Delete] [Delete and Lock User]

reduce前面缺少 return 自定义 prod(L)函数缺少返回值 所以输出None

from functools import reduce

def prod(L): def C(a,b): return a*b return reduce(C,L)

L=[3,5,7,9] print ('357*9=',prod(L))

**函数C有返回值,但是prod没有返回值。

```

范巴i特

#4 Created at ... [Delete] [Delete and Lock User]

理解了,谢谢!


  • 1

Reply