日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

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

系統 2044 0

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

總結Python中邏輯運算符的使用_第1張圖片

?示例:

試試下面的例子就明白了所有的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"


          

當執行上面的程序它會產生以下結果:

            
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


          


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 印江| 山阴县| 兴隆县| 嫩江县| 息烽县| 平罗县| 健康| 和田县| 陕西省| 平江县| 扶沟县| 河津市| 恩平市| 德兴市| 寿阳县| 霍山县| 修文县| 基隆市| 偃师市| 星座| 东明县| 石河子市| 乐陵市| 安宁市| 保定市| 四平市| 桐柏县| 东阿县| 梁山县| 张家界市| 称多县| 高碑店市| 呼玛县| 阿荣旗| 金沙县| 贞丰县| 乡宁县| 南和县| 宣恩县| 肥城市| 永昌县|