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

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

系統 2227 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條評論
主站蜘蛛池模板: 青海省| 浦城县| 且末县| 尉犁县| 松江区| 桂阳县| 石棉县| 乾安县| 时尚| 巴中市| 凤城市| 尼木县| 阳朔县| 东至县| 和硕县| 曲周县| 浦县| 观塘区| 和龙市| 泸西县| 蒙阴县| 鹤山市| 堆龙德庆县| 本溪市| 潜山县| 谷城县| 老河口市| 宜兰市| 泽库县| 成都市| 林芝县| 德格县| 聂拉木县| 个旧市| 盐亭县| 峡江县| 五寨县| 南溪县| 阿坝县| 屏东县| 沐川县|