python中int和float的区别 您所在的位置:网站首页 python中eval和float的区别6 python中int和float的区别

python中int和float的区别

2023-09-17 12:00| 来源: 网络整理| 查看: 265

Python 数字类型 int float

数字常量

int:  一般的整数,

long: 长整型,2.x版本需在数字后加 “L” 或 “l” ,表示长整型 如 100000000L; python3.x 版本后不分长整型,统一为int,不可加 “L” 或 “l”

float: 浮点数,1.0 也为浮点数,float 可强制转换为 int,取整;

1 print(type(1234))2 print(type(-24))3 print(type(0))4 print(type(2147483647)) #为int

5 print(type(2147483648)) #>=2^31 为long Python2.x ; Python3.x long 和 int 合并为 int

6 i = 1l #Python2.x 表示long,Python3 会报错

7 print(i,type(i))8 print(type(i))9 print(type(1e+1)) #e表示法为浮点型

10 print(int(1e+20)) #强制转换为int

11 print(int(1e+30)) #超长精度丢失

12 print(type(1.0)) #小数表示为float

13 print(int(1.999)) #int()强制转换为int 会把float取整

数字计算

加减乘数运算

1 a=1

2 b=2

3 c=2.0

4 print(a+b)5 print(type(a+b))6 print(a-c) #输出 -1.0

7 print(type(a+c)) #有浮点型加入,



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有