Python学习第五天-数字类型(下)

[复制链接]
15271953841 发表于 2024-1-30 10:55:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
3/2
1.5
3//2
1
-3//2
-2
3%2
1
6%2
0
-3%2
1
divmod(3,2)    (返回(x//y,x%y)),相当于求商(商是向下取整数)和余数
(1, 1)
divmod(-3,2)
(-2, 1)
x=-3.14
abs(x)     (绝对值)
3.14
y=-520
abs(y)
520
z=1+2j
abs(z)      (求复数的模的绝对值,就是求实部的平方与虚部的平方的和算术平方根)
2.23606797749979
int(520)
520
int(3.14)        (截取整数部分)
3
int(9.99)
9
float("3.14")     (将字符转化成浮点数,就是含有小数部分的数)
3.14
float(520)
520.0
float("+116")
116.0
float("+1e6")        (科学计数法1e6=1x10的5次方)
1000000.0
float("+1E6")
1000000.0
complex("1+2j")
(1+2j)
complex("1 + 2j")       (字符串中间不能有空格)
Traceback (most recent call last):
  File "<pyshell#23>", line 1, in <module>
    complex("1 + 2j")
ValueError: complex() arg is a malformed string
pow(2,3)            (求2的3次方)
8
2**3
8
pow(2,-3)
0.125
2**-3
0.125
pow(2,3,5)             (求2的3次方除以5的余数)
3
2**3%5
3
关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:admin@discuz.vip

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鄂ICP备13007585号-4

在本发帖
关注公众号
QQ客服返回顶部