Python 7天快速入門完整視頻教程:https://www.bilibili.com/video/BV1o84y1Z7J1
Python算數(shù)運算符
Python支持所有的基本算術(shù)運算符,這些算術(shù)運算符用于執(zhí)行基本的數(shù)學(xué)運算,如加、減、乘、除和求余等。下面是7個基本的算術(shù)運算符。
以下,假設(shè)變量a為10,變量b為21:
實例代碼:
# 定義變量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