马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
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.
123456789/987654321(整数运算非常准确)
0.1249999988609375
6/2
3.0
0.1+0.2
0.30000000000000004(但是小数运算不准确,因为小数以浮点数形式存放,需要用到decimal模块)
i=0
while i<1:
i=i+0.1
print(i)
0.1
0.2
0.30000000000000004
0.4
0.5
0.6
0.7
0.7999999999999999
0.8999999999999999
0.9999999999999999
1.0999999999999999
0.3==0.1+0.2
False
0.3<0.1+0.2
True
import decimal (用之前需要导入decimal模块)
a=decimal.Decimal("0.1") (再运用decimal.Decimal()函数)
b=decimal.Decimal("0.2")
print(a+b)
0.3
c=decimal.Decimal("0.3")
c==a+b
True
0.00005
5e-05 (科学计数法,5x10的-5次方)
1+2j (复数分实部和虚部,他们都以浮点数形式存放)
(1+2j)
x=1+2j
x.real
1.0
x.rmag
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
x.rmag
AttributeError: 'complex' object has no attribute 'rmag'. Did you mean: 'imag'?
x.imag
2.0
|