推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
Kung815
V2EX  ›  Python

为什么这个接受一个 list 并求积的函数返回 none?

  •  
  •   Kung815 · Aug 1, 2017 · 3362 views
    This topic created in 3352 days ago, the information mentioned may be changed or developed.
    如图

    8 replies  •  2017-08-09 21:24:33 +08:00
    lichun
        1
    lichun  
       Aug 1, 2017
    return 呢?
    fzxml
        2
    fzxml  
       Aug 1, 2017
    看标题我就猜没 return 23333 毕竟我也碰到过
    ryd994
        3
    ryd994  
       Aug 1, 2017 via Android
    prod = lambda L: reduce (lambda x,y : x*y , L)
    唔………
    感觉又是一行无法维护的 lambda 地狱………
    ryd994
        4
    ryd994  
       Aug 1, 2017 via Android
    def prod(L):
    return reduce(lambda x,y : x*y, L)

    这样好点
    Kung815
        5
    Kung815  
    OP
       Aug 2, 2017
    @fzxml 不太明白, return 我不是已经加了嘛
    Kung815
        6
    Kung815  
    OP
       Aug 2, 2017
    @lichun 已经加了 return 了
    fzxml
        7
    fzxml  
       Aug 3, 2017
    @Kung815
    ```
    from functools import reduce

    def prod(L):
    def qiuji(x, y):
    return x * y
    return reduce(qiuji, L)
    print(prod([3, 5, 7, 8]))
    ```
    symons
        8
    symons  
       Aug 9, 2017
    你这个没有 return 啊,prod 函数得有一个返回值
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2581 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 03:00 · PVG 11:00 · LAX 20:00 · JFK 23:00
    ♥ Do have faith in what you're doing.