第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么會出現(xiàn)這樣的情況

為什么會出現(xiàn)這樣的情況

vicety 2016-06-30 17:55:04
s = set(['Adam', 'Lisa', 'Paul'])L = ['Adam', 'Lisa', 'Bart', 'Paul']print True == True ? ? #得到Trueprint 'Adam' in s????#得到Trueprint 'Adam' in s == True????#得到False如題
查看完整描述

2 回答

已采納
?
秋名山車神

TA貢獻54條經(jīng)驗 獲得超303個贊

說實話,這個問題我之前也不知道是為什么,于是抱著求知的心態(tài),問了國外的大神,Михаил Никонов的回答原文如下:

It's because of comparison operator chaining, I think. In Python, expression (x < y < z) is, unlike in C, equivalent to (x < y and y < z), and that can be used for any sequence of comparisons (including membership tests). So basically, without parentheses, your last expression is equivalent to ('a' in 'abc' and 'abc' == True), or so it seems.?

翻譯過來差不多就是,print('a' in 'abc' == True) 這種表達式,在Python里面不像C語言那樣,它必須要增加一個括號:print(('a' in 'abc') == True) 這樣才對,如果不增加括號,就相當于print('a' in 'abc' and 'abc' == True) 結果當然是 False。

查看完整回答
反對 回復 2016-07-01
  • vicety
    vicety
    明白了 多謝!
  • 秋名山車神
    秋名山車神
    https://docs.python.org/3/reference/expressions.html#comparisons 這里官方文檔也說明了這個事情
?
秋名山車神

TA貢獻54條經(jīng)驗 獲得超303個贊

感謝你的這個問題,學習了。

查看完整回答
1 反對 回復 2016-07-01
  • 2 回答
  • 1 關注
  • 1586 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號