欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

總結Python中邏輯運算符的使用

 更新時間:2015年05月13日 12:19:28   投稿:goldensun  
這篇文章主要介紹了總結Python中邏輯運算符的使用,是Python學習當中的基礎知識,需要的朋友可以參考下

下表列出了所有Python語言支持的邏輯運算符。假設變量a持有10和變量b持有20,則:

2015513121854474.jpg (586×254)

 示例:

試試下面的例子就明白了所有的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)建、變形(升降維等)、計算、取值、復制、分割、合并

    這篇文章主要介紹了Numpy對數(shù)組的操作:創(chuàng)建、變形(升降維等)、計算、取值、復制、分割、合并,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-08-08
  • python密碼錯誤三次鎖定(實例講解)

    python密碼錯誤三次鎖定(實例講解)

    下面小編就為大家分享一篇python密碼錯誤三次鎖定的實例講解。具有很好的參考價值。希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-11-11
  • python版簡單工廠模式

    python版簡單工廠模式

    這篇文章主要為大家詳細介紹了python版簡單工廠模式,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • python合并兩個字典的方法總結

    python合并兩個字典的方法總結

    在Python中,有多種方法可以通過使用各種函數(shù)和構造函數(shù)來合并字典,在本文中,我們將討論一些合并字典的方法,有需要的小伙伴可以參考一下·
    2023-09-09
  • python字符串替換re.sub()實例解析

    python字符串替換re.sub()實例解析

    這篇文章主要介紹了python字符串替換re.sub()實例解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-02-02
  • Python序列類型的打包和解包實例

    Python序列類型的打包和解包實例

    今天小編就為大家分享一篇Python序列類型的打包和解包實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • Python reques接口測試框架實現(xiàn)代碼

    Python reques接口測試框架實現(xiàn)代碼

    這篇文章主要介紹了Python reques接口測試框架實現(xiàn)代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-07-07
  • Python中常見的數(shù)據(jù)類型小結

    Python中常見的數(shù)據(jù)類型小結

    這篇文章主要對Python中常見的數(shù)據(jù)類型進行了總結歸納,很有參考借鑒價值,需要的朋友可以參考下
    2015-08-08
  • 使用Playwright進行視覺回歸測試詳解

    使用Playwright進行視覺回歸測試詳解

    這篇文章主要介紹了使用Playwright進行視覺回歸測試詳解,視覺回歸測試是一種軟件測試技術,專注于檢測Web應用程序或網(wǎng)站的用戶界面中的視覺變化和差異,需要的朋友可以參考下
    2023-08-08
  • Python字符與ASCII碼相互轉(zhuǎn)換方法

    Python字符與ASCII碼相互轉(zhuǎn)換方法

    在做python編程時,碰到了需要將字母轉(zhuǎn)換成ascii碼的需求,所以下面這篇文章主要給大家介紹了關于Python字符與ASCII碼相互轉(zhuǎn)換的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-06-06

最新評論