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

實例說明Python中比較運算符的使用

系統 2132 0

下表列出了所有Python語言支持的比較操作符。假設變量a持有10和變量b持有20,則:

實例說明Python中比較運算符的使用_第1張圖片

?例如:

試試下面的例子就明白了所有的Python編程語言提供的比較操作符:

            
#!/usr/bin/python

a = 21
b = 10
c = 0

if ( a == b ):
  print "Line 1 - a is equal to b"
else:
  print "Line 1 - a is not equal to b"

if ( a != b ):
  print "Line 2 - a is not equal to b"
else:
  print "Line 2 - a is equal to b"

if ( a <> b ):
  print "Line 3 - a is not equal to b"
else:
  print "Line 3 - a is equal to b"

if ( a < b ):
  print "Line 4 - a is less than b" 
else:
  print "Line 4 - a is not less than b"

if ( a > b ):
  print "Line 5 - a is greater than b"
else:
  print "Line 5 - a is not greater than b"

a = 5;
b = 20;
if ( a <= b ):
  print "Line 6 - a is either less than or equal to b"
else:
  print "Line 6 - a is neither less than nor equal to b"

if ( b >= a ):
  print "Line 7 - b is either greater than or equal to b"
else:
  print "Line 7 - b is neither greater than nor equal to b"


          

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

            
Line 1 - a is not equal to b
Line 2 - a is not equal to b
Line 3 - a is not equal to b
Line 4 - a is not less than b
Line 5 - a is greater than b
Line 6 - a is either less than or equal to b
Line 7 - b is either greater than or equal to b


          



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

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

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

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 嘉黎县| 曲麻莱县| 治县。| 佳木斯市| 静海县| 个旧市| 南充市| 宜黄县| 三河市| 开江县| 宁都县| 方山县| 鹤峰县| 林周县| 龙游县| 申扎县| 汽车| 湖北省| 华宁县| 旬邑县| 曲阳县| 尚志市| 盘山县| 万年县| 呼玛县| 临泉县| 安阳县| 南召县| 濮阳县| 上高县| 开封县| 盱眙县| 昌图县| 广灵县| 吉隆县| 吉水县| 措美县| 霍山县| 彭山县| 故城县| 厦门市|