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

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

系統 2126 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條評論
主站蜘蛛池模板: 宁阳县| 宁明县| 亚东县| 万安县| 思茅市| 温宿县| 密山市| 故城县| 尉犁县| 若尔盖县| 同仁县| 南阳市| 苗栗县| 临沭县| 乌什县| 沧源| 遂川县| 苍梧县| 龙陵县| 温州市| 隆回县| 和政县| 喀喇| 新乐市| 介休市| 南雄市| 揭东县| 若尔盖县| 南宁市| 广昌县| 永安市| 东辽县| 嘉义县| 普兰县| 镇江市| 龙江县| 综艺| 县级市| 金溪县| 平利县| 喜德县|