下表列出了所有Python語(yǔ)言支持的算術(shù)運(yùn)算符。假設(shè)變量a持有10和變量b持有20,則:

例子:
試試下面的例子就明白了所有的Python編程語(yǔ)言提供了算術(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
當(dāng)執(zhí)行上面的程序,它會(huì)產(chǎn)生以下結(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
新聞熱點(diǎn)
疑難解答
圖片精選