python 中的数值运算

 时间:2026-04-24 03:45:24

1、使用内置的type函数查看变量的类型。

spam_amount = 0

print(type(spam_amount))

print(type(1.2))

python 中的数值运算

2、常用的数值运算符

a + b :表示a加上b

a - b :表示a减b

a * b : 表示a乘以b

a / b : a除以b

a // b :a除以b取整

a % b :a除以b取余

a ** b :a的b次方

-a :负a

python 中的数值运算

3、一个例子:

hat_height_cm = 25

my_height_cm = 190

# How tall am I, in meters, when wearing my hat?

total_height_meters = hat_height_cm + my_height_cm / 100

print("Height in meters =", total_height_meters, "?")

python 中的数值运算

4、最大最小函数max,min

print(min(1, 2, 3))

print(max(1, 2, 3))

python 中的数值运算

5、去绝对值函数abs

print(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 中的数值运算

  • char函数什么意思怎么用
  • 如何用matlab求带绝对值函数的导数?
  • 如何使用python语言中pandas模块中的iloc方法
  • Mathematica应用——有趣的绝对值方程
  • 龙贝格算法一
  • 热门搜索
    .bak是什么文件 申论是什么 放屁臭是什么原因 娈童是什么意思 什么是小说 花椰菜是什么 有什么好吃的零食 tablet是什么意思 绿茶什么时候喝最好 准贷记卡是什么意思