Files
2025PY/day03/05-内置的数字运算函数.py
2025-05-22 16:50:44 +08:00

28 lines
735 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 内置函数python语言设定好具有特定的功能
# 一.前面学过的内置函数
# 1.print函数打印
# 2.input函数输入
# 3.type函数检测类型
# 4.int/float/str :类型转换
# 二.内置的数值运算函数
# 1.abs() 取括号里面数字的绝对值
num=-100
print(abs(num))
# 2.divmod(整数商,余数)
print(divmod(9,2)) #(4,1) 4是9和2的商的整数部分 1是9和2的余数
# 3.pow(x,y,z) (x**y)%z 参数z可以忽略
# 求幂
print(2**3)
print(pow(2,3))
# 4.round(x,n)对x求四舍五入 保留n位小数
print(round(3.6678))
print(round(3.6678,3))
# 5.max(x1,x2,x3...xn) 返回一个最大值
# min(x1,x2,x3...xn) 返回一个最小值
print(max(23,45,67,89))
print(min(23,45,67,89))