Python知識分享網(wǎng) - 專業(yè)的Python學(xué)習(xí)網(wǎng)站 學(xué)Python,上Python222
Python算數(shù)運算符
匿名網(wǎng)友發(fā)布于:2023-09-11 14:35:50
(侵權(quán)舉報)

Python 7天快速入門完整視頻教程https://www.bilibili.com/video/BV1o84y1Z7J1

 

Python算數(shù)運算符

 

 

Python支持所有的基本算術(shù)運算符,這些算術(shù)運算符用于執(zhí)行基本的數(shù)學(xué)運算,如加、減、乘、除和求余等。下面是7個基本的算術(shù)運算符。

以下,假設(shè)變量a為10,變量b為21:

 

Python算數(shù)運算符 圖1

 

實例代碼:

 

# 定義變量a值為10
a = 10

# 定義變量b值為21
b = 21

print("a+b=", a + b)
print("a-b=", a - b)
print("a*b=", a * b)
print("b/a=", b / a)
print("a**b=", a ** b)
print("b//a=", b // a)
print("b%a=", b % a)

 

執(zhí)行結(jié)果:

 

a+b= 31
a-b= -11
a*b= 210
b/a= 2.1
a**b= 1000000000000000000000
b//a= 2
b%a= 1

Process finished with exit code 0

 

 

 

轉(zhuǎn)載自: