QQ登录

只需一步,快速开始

开启左侧

python学习第四天——数字类型(上)

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

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

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

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
客服热线
400-1234-888 周一至周日:09:00 - 21:00
公司地址:襄阳市樊城区长虹路现代城5号楼188

创客帮MAKER.BAND青少年创客创意社区是一个融教育、科技、体育资讯为一体的综合服务平台,专注于教育创新、专注于科技体育、专注于教育资讯。

Powered by Discuz! X3.4 © 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表