import math#浮点数运算
import cmath#复数运算
import decimal#固定精度的数据
import fractions#分数,实现一个有理数对象
import random#随机数
#三角函数
x = math.sin(30/180*math.pi)
#以a为底的x的对数
a=2
y = math.log(x,a)
#x的a次方
y = math.pow(x, a)
#复数:极坐标转为直角坐标
x = cmath.polar(4+3j)
#复数:极坐标转为直角坐标
x = cmath.rect(6, math.pi/3)
#e的x次方
y = cmath.exp(x)
#求对数、平方根都可以用cmath.函数来求
#得到固定精度的数据不用担心精度丢失
#输出x和y会发现y的精度有问题
x =decimal.Decimal('0.00022')
x = x-decimal.Decimal('0.00022512')
y = 0.00022-0.00022512
#生成对应的分数
x = fractions.Fraction('1.5')
#或者fractions.Fraction(3,2)
#将浮点数转为分数,可能有误差
x = fractions.Fraction(1.5)
#生成随机实数[1,10)
x = random.randint(1, 10)
#生成随机浮点数[1,10)
x = random.uniform(1, 10)
#生成随机整数数[1,10]
x = random.randint(1, 10)
#生成k位的二进制随机整数数,以10进制表现出来
k = 10
x = random.getrandbits(k)
#random.choice()从指定的序列中随机选择一个元素
#random.sample(p, k)从序列p中随机抽取k个元素
#random.shuffle(p)将序列p随机重新排列(p必须是可变序列)