您的位置:首页 > 编程语言 > Python开发

python | 数据类型 | 数值

2018-01-08 00:01 74 查看
# encoding: utf-8
import math
import random

# 绝对值
print(abs(-32))

# 最大值
print(max(13, 32, 453, 54, 43, 43, 334))

# 最小值
print(min(13, 32, 453, 54, 43, 43, 334))

# 四舍五入
print(round(3.14743, 2))

# 次方
print(pow(2, 4))

# 向上取整
print(math.ceil(3.1))

# 向下取整
print(math.floor(3.9))

# 求开方
print(math.sqrt(9))

# 求对数
print(math.log(10000, 100))

# 随机函数
# 默认范围为[0,1)内的随机小数
print(random.random())
# 范围为序列中的数
print(random.choice(range(1, 101)))
seq = [1, 2, 3, 4, 5, 6, 7]
print(random.choice(seq))
# 范围为[x, y]内的随机小数
print(random.uniform(1, 3))
# 范围为[x, y]内的随机整数
print(random.randint(1, 3))
# 范围为[x, y)内的随机整数,可设置步长
print(random.randrange(1, 13, 2))

# 三角函数
# 求sin(30)
print(math.sin(math.pi * 1 / 6))
# 角度转弧度
print(math.sin(math.radians(30)))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python