preview.jpg
最近學(xué)習(xí) Python,發(fā)現(xiàn)一個很尷尬的問題塔淤。實在是覺得羞恥摘昌,我也是學(xué)過 Java、C#高蜂,了解 C聪黎、C++ ,項目經(jīng)驗有五年以上的猿了 ??????
說正事
Python 中的與或非運算符相信各位大神已經(jīng)非常熟悉了
下面代碼請做心里運算(坦然面對自己??)
print(True and False)
print(True and False or False)
print(False and False or True and not 1 == 1)
print(True and False or not False)
print(False and True or not False)
揭曉謎底
True and False = False
True and False or False = False
False and False or True and not 1 == 1 = False
True and False or not False = True
False and True or not False = True
坦白的說备恤,前面兩句的結(jié)果我是知道的稿饰,但是當(dāng)看到第3行時我徹底石化了锦秒,我敲了這好幾年的假代碼?內(nèi)心世界真的崩塌了
大神看到這種題可能就是會心一笑看煞筆的心情喉镰,但是就算只有我一個人栽在這里旅择,我也想提醒各位,基礎(chǔ)真的很重要
上面這些代碼其實主要涉及到 Python 中的運算符優(yōu)先級
優(yōu)先級排序如下
not > and > or
not > and > or
not > and > or
過于羞恥侣姆,大神勿噴生真,溜了溜了 ??