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
s04
V2EX  ›  Python

Checkio 题目求赐教:关于检查序列是否为空

  •  
  •   s04 · 2018-06-13 18:03:35 +08:00 · 1616 次点击
    这是一个创建于 2115 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本人在解决检查序列是否为空白的时候用了 if args is None:语句,但 IDE 却返回我的错误是 max ()函数里边的参数为空。后来我在网上找了 if not args:却解决问题了,求有深入了解大佬解释一下。源代码如下。

    def checkio(*args): if args is None: #if not args: return 0 #"Empty" else: max_num = max(args) min_num = min(args) answer = max_num - min_num print ("%s-%s=%s" % (max_num, min_num, answer)) return answer

    #These "asserts" using only for self-checking and not necessary for auto-testing if name == 'main': def almost_equal(checked, correct, significant_digits): precision = 0.1 ** significant_digits return correct - precision < checked < correct + precision

    assert almost_equal(checkio(1, 2, 3), 2, 3), "3-1=2"
    assert almost_equal(checkio(5, -5), 10, 3), "5-(-5)=10"
    assert almost_equal(checkio(10.2, -2.2, 0, 1.1, 0.5), 12.4, 3), "10.2-(-2.2)=12.4"
    assert almost_equal(checkio(), 0, 3), "Empty"
    print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
    

    3 条回复    2018-06-13 18:21:33 +08:00
    8Cangtou
        1
    8Cangtou  
       2018-06-13 18:16:12 +08:00   ❤️ 1
    assert almost_equal(checkio(), 0, 3), "Empty"

    None != []
    ranleng
        2
    ranleng  
       2018-06-13 18:18:46 +08:00 via Android   ❤️ 1
    None 是 None, 空值是空值
    8Cangtou
        3
    8Cangtou  
       2018-06-13 18:21:33 +08:00
    @8Cangtou 为空,不是[]
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1042 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:32 · PVG 06:32 · LAX 15:32 · JFK 18:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.