Python數(shù)字
數(shù)字?jǐn)?shù)據(jù)類型用于存儲(chǔ)數(shù)值。
他們是不可改變的數(shù)據(jù)類型,這意味著改變數(shù)字?jǐn)?shù)據(jù)類型會(huì)分配一個(gè)新的對(duì)象。
當(dāng)你指定一個(gè)值時(shí),Number對(duì)象就會(huì)被創(chuàng)建:
var1 = 1
var2 = 10
您也可以使用del語句刪除一些對(duì)象引用。
del語句的語法是:
del var1[,var2[,var3[....,varN]]]]
您可以通過使用del語句刪除單個(gè)或多個(gè)對(duì)象。例如:
del var
del var_a, var_b
Python支持四種不同的數(shù)值類型:
- int(有符號(hào)整型)
- long(長整型[也可以代表八進(jìn)制和十六進(jìn)制])
- float(浮點(diǎn)型)
- complex(復(fù)數(shù))
實(shí)例
一些數(shù)值類型的實(shí)例:
長整型也可以使用小寫"L",但是還是建議您使用大寫"L",避免與數(shù)字"1"混淆。Python使用"L"來顯示長整型。
Python還支持復(fù)數(shù),復(fù)數(shù)由實(shí)數(shù)部分和虛數(shù)部分構(gòu)成,可以用a + bj,或者complex(a,b)表示, 復(fù)數(shù)的實(shí)部a和虛部b都是浮點(diǎn)型。
Python算術(shù)運(yùn)算符
以下假設(shè)變量a為10,變量b為20:
以下實(shí)例演示了Python所有算術(shù)運(yùn)算符的操作:
#!/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
以上實(shí)例輸出結(jié)果:
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
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元

