總結(jié)Python中邏輯運(yùn)算符的使用
下表列出了所有Python語言支持的邏輯運(yùn)算符。假設(shè)變量a持有10和變量b持有20,則:
示例:
試試下面的例子就明白了所有的Python編程語言提供了邏輯運(yùn)算符:
#!/usr/bin/python a = 10 b = 20 c = 0 if ( a and b ): print "Line 1 - a and b are true" else: print "Line 1 - Either a is not true or b is not true" if ( a or b ): print "Line 2 - Either a is true or b is true or both are true" else: print "Line 2 - Neither a is true nor b is true" a = 0 if ( a and b ): print "Line 3 - a and b are true" else: print "Line 3 - Either a is not true or b is not true" if ( a or b ): print "Line 4 - Either a is true or b is true or both are true" else: print "Line 4 - Neither a is true nor b is true" if not( a and b ): print "Line 5 - Either a is not true or b is not true" else: print "Line 5 - a and b are true"
當(dāng)執(zhí)行上面的程序它會(huì)產(chǎn)生以下結(jié)果:
Line 1 - a and b are true Line 2 - Either a is true or b is true or both are true Line 3 - Either a is not true or b is not true Line 4 - Either a is true or b is true or both are true Line 5 - Either a is not true or b is not true
相關(guān)文章
Numpy對(duì)數(shù)組的操作:創(chuàng)建、變形(升降維等)、計(jì)算、取值、復(fù)制、分割、合并
這篇文章主要介紹了Numpy對(duì)數(shù)組的操作:創(chuàng)建、變形(升降維等)、計(jì)算、取值、復(fù)制、分割、合并,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08python密碼錯(cuò)誤三次鎖定(實(shí)例講解)
下面小編就為大家分享一篇python密碼錯(cuò)誤三次鎖定的實(shí)例講解。具有很好的參考價(jià)值。希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2017-11-11Python reques接口測(cè)試框架實(shí)現(xiàn)代碼
這篇文章主要介紹了Python reques接口測(cè)試框架實(shí)現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07Python中常見的數(shù)據(jù)類型小結(jié)
這篇文章主要對(duì)Python中常見的數(shù)據(jù)類型進(jìn)行了總結(jié)歸納,很有參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08使用Playwright進(jìn)行視覺回歸測(cè)試詳解
這篇文章主要介紹了使用Playwright進(jìn)行視覺回歸測(cè)試詳解,視覺回歸測(cè)試是一種軟件測(cè)試技術(shù),專注于檢測(cè)Web應(yīng)用程序或網(wǎng)站的用戶界面中的視覺變化和差異,需要的朋友可以參考下2023-08-08