False == (False in [False]) - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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

False == (False in [False])

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

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

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

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

    一个逗号就不一样拉~~
    fourstring
        10
    fourstring  
       Oct 17, 2015
    @hahastudio 就是说,在这种情境下, Python 不会像 if object 这样调用对象的__bool__()方法来返回一个 bool 值进行计算?
    hahastudio
        11
    hahastudio  
       Oct 17, 2015
    @fourstring 你遇到的不是一个 object ,是一个表达式啊
    siteshen
        12
    siteshen  
       Oct 17, 2015
    @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
        13
    fourstring  
       Oct 17, 2015
    @siteshen
    @hahastudio
    感谢,一时没想明白……
    easyhappy
        14
    easyhappy  
       Oct 19, 2015
    False == False in [False]
    >>>True

    为什么是 True ?
    About     Help     Advertise     Blog     API     FAQ     Solana     3280 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 48ms UTC 13:31 PVG 21:31 LAX 06:31 JFK 09:31
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86