目录

python基本数据类型int

python基本数据类型——int

一、int的范围

python2:

在32位机器上,整数的位数为32位,取值范围为-231~231-1;

在64位系统上,整数的位数为64位,取值范围为-263~263-1;

python3:

理论上长度是无限的(只要内存足够大)

二、python内存机制

在一般情况下当变量被赋值后,内存和变量的关系如下:

https://i-blog.csdnimg.cn/blog_migrate/95a3ecf98e951dad0a34bc5bebb42409.png

特殊情况:

python内的优化机制(不论是2.7还是3.5都有):

-5 ~ 257 之间的数,如果使用第一种赋值方式,那么他们依然属于同一块内存(可以用id查看)

三、源码

https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif int

小知识点:

在python2中:

https://i-blog.csdnimg.cn/blog_migrate/69c5a8ac3fa60e0848d784a6dd461da6.gif

test = 9 / 2 
输出—— 4

from **future** import division
test = 9 / 2
输出—— 4.5

https://i-blog.csdnimg.cn/blog_migrate/69c5a8ac3fa60e0848d784a6dd461da6.gif

而在 python3 中:

test = 9 / 2
输出—— 4.5