總結Python中邏輯運算符的使用
更新時間:2015年05月13日 12:19:28 投稿:goldensun
這篇文章主要介紹了總結Python中邏輯運算符的使用,是Python學習當中的基礎知識,需要的朋友可以參考下
下表列出了所有Python語言支持的邏輯運算符。假設變量a持有10和變量b持有20,則:
示例:
試試下面的例子就明白了所有的Python編程語言提供了邏輯運算符:
#!/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"
當執(zhí)行上面的程序它會產(chǎn)生以下結果:
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
相關文章
Numpy對數(shù)組的操作:創(chuàng)建、變形(升降維等)、計算、取值、復制、分割、合并
這篇文章主要介紹了Numpy對數(shù)組的操作:創(chuàng)建、變形(升降維等)、計算、取值、復制、分割、合并,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-08-08