Python數字
數字數據類型用于存儲數值。
他們是不可改變的數據類型,這意味著改變數字數據類型會分配一個新的對象。
當你指定一個值時,Number對象就會被創建:
var1 = 1 var2 = 10
您也可以使用del語句刪除一些對象引用。
del語句的語法是:
del var1[,var2[,var3[....,varN]]]]
您可以通過使用del語句刪除單個或多個對象。例如:
del var del var_a, var_b
Python支持四種不同的數值類型:
- int(有符號整型)
- long(長整型[也可以代表八進制和十六進制])
- float(浮點型)
- complex(復數)
實例
一些數值類型的實例:
長整型也可以使用小寫"L",但是還是建議您使用大寫"L",避免與數字"1"混淆。Python使用"L"來顯示長整型。
Python還支持復數,復數由實數部分和虛數部分構成,可以用a + bj,或者complex(a,b)表示, 復數的實部a和虛部b都是浮點型。
Python算術運算符
以下假設變量a為10,變量b為20:
以下實例演示了Python所有算術運算符的操作:
#!/usr/bin/python a = 21 b = 10 c = 0 c = a + b print "Line 1 - Value of c is ", c c = a - b print "Line 2 - Value of c is ", c c = a * b print "Line 3 - Value of c is ", c c = a / b print "Line 4 - Value of c is ", c c = a % b print "Line 5 - Value of c is ", c a = 2 b = 3 c = a**b print "Line 6 - Value of c is ", c a = 10 b = 5 c = a//b print "Line 7 - Value of c is ", c
以上實例輸出結果:
Line 1 - Value of c is 31 Line 2 - Value of c is 11 Line 3 - Value of c is 210 Line 4 - Value of c is 2 Line 5 - Value of c is 1 Line 6 - Value of c is 8 Line 7 - Value of c is 2
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

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