V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
Vegetables
V2EX  ›  Python

为什么输入结果是 None?

  •  
  •   Vegetables · 2018-11-12 22:03:40 +08:00 · 1584 次点击
    这是一个创建于 1985 天前的主题,其中的信息可能已经有所发展或是发生改变。
    6 条回复    2018-11-12 23:19:14 +08:00
    luguhu
        1
    luguhu  
       2018-11-12 22:25:43 +08:00 via Android
    递归 2//2 等于 0
    lifengming
        2
    lifengming  
       2018-11-12 22:40:29 +08:00   ❤️ 1
    递归调用时,else 那里没有用 return,丢失数据了
    ericls
        3
    ericls  
       2018-11-12 22:42:38 +08:00 via iPhone   ❤️ 1
    lifengming
        4
    lifengming  
       2018-11-12 22:47:04 +08:00   ❤️ 1
    还要一个问题,lz 你最后字符串应该是错了吧,取反是[::-1]
    Vegetables
        5
    Vegetables  
    OP
       2018-11-12 23:06:52 +08:00
    @lifengming 嗯 取反错了 else 里加上 return 我得再去看看递归该怎么写
    lasuar
        6
    lasuar  
       2018-11-12 23:19:14 +08:00   ❤️ 1
    a. [:-1] 你是想干嘛
    b. python 递归在调用的地方得带上 return,不然第一次出去的时候函数运行的结果就是 None,后面永远是 None。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2565 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:24 · PVG 09:24 · LAX 18:24 · JFK 21:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.