Features summary:
Integer (int): Usually called an integer or integer, it is a positive or negative number without a decimal point
Floating point number (float): a value with a decimal point, which can also be expressed in scientific notation
Complex number (complex): consists of a real number part and an imaginary number part. The expression is: a + bj or complex(a, b), where a is the real part and b is the imaginary part
Common categories of numbers:
- Mathematical functions (mainly perform various mathematical calculations, such as calculating absolute values, power operations, square roots, etc., mainly defined in the math module)
- Random number function (mainly used for processing random numbers, for example, generating random numbers is mainly defined in the random module)
- Trigonometric function (mainly used to convert numerical values into corresponding triangular radian values, mainly defined in cmath module)
Test result display:
import cmath
import random
a=12.1
b=10
#浮点数转换为数字
print(int(a))
#整数转换为浮点数
print(float(b))
#a,b转换为复数
print(complex(a,b))
import math #数学函数计算
c=10
d=2.3
f=-10
#绝对值计算
print(abs(f))
# 反回最大值
print(max(c, d))
# 返回最小值
print(min(c, d))
#计算y的平方
print(pow(c,2))
#计算开平方
print(math.sqrt(c))
# 计算随机数random
list=[1,2,3,4,5,6]
#从list里面任意选择一个
print(random.choice(list))
#从(0-1)之间任意选择一个数
print(random.random())
#从指定的范围(2-100按4递增的数据集)中随机选中一个
print(random.randrange(0,100,4))
#三角函数
l=90
#反余弦的弧度值
print(cmath.acos(l))
#正弦的弧度值
print(cmath.sin(l))
#余弦的弧度值
print(cmath.cos(l))
#3.14
print(cmath.pi)