python 中的数值运算

时间:2024-10-12 01:52:12

1、使用内置的type函数查看变量的类型。spam_amount = 0print(type(spam_amount))print(type(1.2))

python 中的数值运算

2、常用的数值运算符a + b :表示a加上ba - 水瑞侮瑜b :表示a减ba * b : 表示a乘以ba / 芟鲠阻缒b : a除以ba // b :a除以b取整a % b :a除以b取余a ** b :a的b次方-a :负a

python 中的数值运算

3、一稍僚敉视个例子:hat_height_cm = 25my_height_cm = 190# How tall am I, in meters, when wearing my hat?total_height_meters = hat_height_cm + my_height_cm / 100print("Height in meters =", total_height_meters, "?")

python 中的数值运算

4、最大最小函数max,minprint(min(1, 2, 3))print(max(1, 2, 3))

python 中的数值运算

5、去绝对值函数absprint(abs(32))print(abs(-32))

python 中的数值运算

6、类型强制转换:print(float(10))print(int(3.33))# They can even be called on strings!print(int('807') + 1)

python 中的数值运算
© 手抄报圈