a = -1 # int
b = 2.0 # float
c = 13.11 # float
d = 3.14j # complex
print(type(a), type(b), type(c), type(d))
print(a + c) # 加:10.11
print(a - c) # 减:-14.11
print(a * c) # 乘:-13.11
print(c // b, c / b, c % b) # 6.0【取整除 - 返回商的整数部分(向下取整)】 6.555【除】 1.1099999999999994【取模 - 返回除法的余数】
print(b ** a) # 0.5
print(abs(a)) # 求绝对值
print(divmod(c, b)) # Return the tuple (x//y, x%y) (6.0, 1.1099999999999994)
print(hex(a)) # -0x1 十六进制
print(oct(a)) # -0o1 八进制
print(max(a, b, c)) # 返回最大值
print(min(a, b, c)) # 返回最小值
print(round(c)) # 四舍五入 13
# print(sorted(a,b,c)) #TypeError: integer argument expected, got float
print(sorted([1, 4, 5, 6, 0, 9])) # 排序:[0, 1, 4, 5, 6, 9]
print(sorted({"b": 1, "a": 2, "c": 3})) # 排序 ['a', 'b', 'c']
print(sum([a, b, c])) # 求和 14.11
"""
跟数字相关的有很多方法,如
常见的加减乘除求余、向上取整、向下取整、四舍五入、平均值、最大值、随机数、圆周率、比较运算、赋值运算、逻辑运算等等
"""
以下内容截图源于菜鸟教程,仅作记录:
Python Number 类型转换

Python数学函数

Python随机数函数

Python三角函数

Python数学常量

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/279735.html