推荐学习书目
› 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
glasslion
V2EX  ›  Python

False == (False in [False])

  •  
  •   glasslion · Oct 16, 2015 · 4842 views
    This topic created in 4036 days ago, the information mentioned may be changed or developed.

    大家觉得这个表达式的值是什么?

    14 replies  •  2015-10-19 23:51:54 +08:00
    nayihz
    nayihz
    Oct 16, 2015
    1
    False
    hahastudio
    hahastudio
    Oct 16, 2015
    2
    False in [False] => True
    False == True => False
    你要是挑个感觉会歧义的也行啊
    aaronlam
    aaronlam
    Oct 16, 2015
    3
    楼上正解
    理解好运算优先级的话,这不是很容易得到答案吗?
    imn1
    imn1
    Oct 16, 2015
    4
    True == (False in [False],)
    这个呢?
    kendetrics
    kendetrics
    Oct 16, 2015
    5
    @imn1 False != [False] => False not in [False], ,对吧?
    Hello1995
    Hello1995
    Oct 16, 2015
    6
    简单粗暴。过程正如 #2 所言。
    hahastudio
    hahastudio
    Oct 16, 2015
    7
    @imn1
    True == tuple => False
    你这也就骗骗连语法都不懂的= =
    imn1
    imn1
    Oct 16, 2015
    8
    @hahastudio
    不是问你,问 LZ 的
    gccplus
    gccplus
    Oct 17, 2015
    9
    True == (False in [False])
    True

    True == (False in [False],)
    False

    一个逗号就不一样拉~~
    fourstring
    fourstring
    Oct 17, 2015
    10
    @hahastudio 就是说,在这种情境下, Python 不会像 if object 这样调用对象的__bool__()方法来返回一个 bool 值进行计算?
    hahastudio
    hahastudio
    Oct 17, 2015
    11
    @fourstring 你遇到的不是一个 object ,是一个表达式啊
    siteshen
    siteshen
    Oct 17, 2015
    12
    @fourstring 另如果所有 a == b 都转换成 bool 类型再比较的话,那么 a == True 或者 a == False 就必然为真了。不是一个物种,你让 python 怎么自动转换。

    () == [] => False
    1 == 1.0 => True
    True == 1 => True
    False == 0 => False
    complex(1,0) == True
    fourstring
    fourstring
    Oct 17, 2015
    13
    @siteshen
    @hahastudio
    感谢,一时没想明白……
    easyhappy
    easyhappy
    Oct 19, 2015
    14
    False == False in [False]
    >>>True

    为什么是 True ?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5125 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 06:39 · PVG 14:39 · LAX 22:39 · JFK 01:39
    ♥ Do have faith in what you're doing.