
作者简介:一名在校计算机学生、每天分享Python的学习经验、和学习笔记。
个人主页:网络豆的主页
目录
本章将会讲解Python编程中的 数值类型 数字计算
- """
- Return the ceiling of x as an Integral.
-
- This is the smallest integer >= x.
- """
- #这是一个最小的整数,还要大于等于X
-
-
- import math #向上取整 得5
-
- print(math.ceil(4.1)) #向上取整
- """
- Return the floor of x as an Integral.
-
- This is the largest integer <= x.
- """
- #这是一个最大的整数还小于等于X
-
- import math
- print(math.floor(4.5)) #向下取整 得4
-
- """ Return x**y (x to the power of y). """
- 返回次幂
- import math
- print(math.pow(2,3)) # x**y 2**3
- """ Return the absolute value of the argument. """
- 这个参数的绝对值
-
- a=-10
- print(abs(a)) #打印取绝对值后的值
- # Python3 进行改良 不再是四舍五入 而是 四舍六入五成偶
- print(round(4.1)) #舍去为4
-
- print(round(4.5)) #舍去为4(Python2和Python3区别 2 中会进入为5 3 中不会)
-
- print(round(4.6)) #进1为5
-
- print(round(3.5)) #4
-
- #vars([object]) -> dictionary 保留小数
-
- print(round(4.5, 1)) #得 4.5
创作不易,求关注,点赞,收藏,谢谢~