前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 标准库 数学计算

python 标准库 数学计算

作者头像
用户5760343
发布2022-01-10 08:10:14
6470
发布2022-01-10 08:10:14
举报
文章被收录于专栏:sktj

1、decimal: from decimal import * print(Decimal.from_float(12.222)) getcontext().prec=6 from decimal import * getcontext().prec = 6 Decimal(1)/Decimal(7) 2、quantize from decimal import * Decimal('50.5679').quantize(Decimal('0.00'))

结果为Decimal('50.57'),结果四舍五入保留了两位小数

3、转为str from decimal import * str(Decimal('3.40').quantize(Decimal('0.0'))) 4、fractions from fractions import Fraction

print(Fraction(3.5)) print(Fraction(5/6)) print(Fraction(5,6)) print(Fraction('5/6')) 5、fractions.Fraction.from_decimal(v) 6、random.randrange()

  • random.randrange(10) 从0-9中取随机整数
  • random.randrange(2,12) 从2-11中取随机整数
  • random.randrange(0,10,2) 从0-9中取随机偶数 7、random.randint() random.randint(a,b)==>random.randrange(a,b+1) 8、random.choice(seq) 从序列中取一个值 9、random.shuffle() 重新排序序列 10 random.simple(population,k) 从序列中去K个值 11 浮点数:
  • random.random() 返回一个左闭右开[0,1.0)区间的浮点数
  • random.uniform(a,b) 返回一个左闭右开[a,b)区间的浮点数 12| math.pi math.e math.isinf() 是否无穷 math.trunc() math.floor() math.ceil() math.modf()返回小数和整数部分 frexp 返回尾数和指数

image.png math.fabs() 绝对值 math.copysign() 返回正确符号 math.pow(x,y) math.sqrt(9.0) math.log math.exp(2) e**2 math.degrees()

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.05.10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 结果为Decimal('50.57'),结果四舍五入保留了两位小数
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档