python | 数据类型 | 数值

# 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)))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值