一、int的范围

2.7:

32位:-231~231-1 64位:-263~263-1

3.5:

在3.5中init长度理论上是无限的

二、python内存机制

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

#方式一
n1 = 123
n2 = 123

#方式二
n1 = 123
n2 = n1

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

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

print(id(n1))       #查看变量的内存地址

二、进制转换

bin()    #把变量转换为2进制
oct() #把变量转换为8进制
int() #把变量转换为10进制
hex() #把变量转换为16进制

三、源码

class int(object):
"""
int(x=0) -> integer
int(x, base=10) -> integer Convert a number or string to an integer, or return 0 if no arguments
are given. If x is a number, return x.__int__(). For floating point
numbers, this truncates towards zero. If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base. The literal can be preceded by '+' or '-' and be surrounded
by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0)
4
"""
def bit_length(self): ; restored from __doc__
"""
int.bit_length() -> int Number of bits necessary to represent self in binary.
>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
"""
return 0 def conjugate(self, *args, **kwargs):
""" Returns self, the complex conjugate of any int. """
pass @classmethod # known case
def from_bytes(cls, bytes, byteorder, *args, **kwargs): ; NOTE: unreliably restored from __doc__
"""
int.from_bytes(bytes, byteorder, *, signed=False) -> int Return the integer represented by the given array of bytes. The bytes argument must be a bytes-like object (e.g. bytes or bytearray). The byteorder argument determines the byte order used to represent the
integer. If byteorder is 'big', the most significant byte is at the
beginning of the byte array. If byteorder is 'little', the most
significant byte is at the end of the byte array. To request the native
byte order of the host system, use `sys.byteorder' as the byte order value. The signed keyword-only argument indicates whether two's complement is
used to represent the integer.
"""
pass def to_bytes(self, length, byteorder, *args, **kwargs): ; NOTE: unreliably restored from __doc__
"""
int.to_bytes(length, byteorder, *, signed=False) -> bytes Return an array of bytes representing an integer. The integer is represented using length bytes. An OverflowError is
raised if the integer is not representable with the given number of
bytes. The byteorder argument determines the byte order used to represent the
integer. If byteorder is 'big', the most significant byte is at the
beginning of the byte array. If byteorder is 'little', the most
significant byte is at the end of the byte array. To request the native
byte order of the host system, use `sys.byteorder' as the byte order value. The signed keyword-only argument determines whether two's complement is
used to represent the integer. If signed is False and a negative integer
is given, an OverflowError is raised.
"""
pass def __abs__(self, *args, **kwargs):
""" abs(self) """
pass def __add__(self, *args, **kwargs):
""" Return self+value. """
pass def __and__(self, *args, **kwargs):
""" Return self&value. """
pass def __bool__(self, *args, **kwargs):
""" self != 0 """
pass def __ceil__(self, *args, **kwargs):
""" Ceiling of an Integral returns itself. """
pass def __divmod__(self, *args, **kwargs):
""" Return divmod(self, value). """
pass def __eq__(self, *args, **kwargs):
""" Return self==value. """
pass def __float__(self, *args, **kwargs):
""" float(self) """
pass def __floordiv__(self, *args, **kwargs):
""" Return self//value. """
pass def __floor__(self, *args, **kwargs):
""" Flooring an Integral returns itself. """
pass def __format__(self, *args, **kwargs):
pass def __getattribute__(self, *args, **kwargs):
""" Return getattr(self, name). """
pass def __getnewargs__(self, *args, **kwargs):
pass def __ge__(self, *args, **kwargs):
""" Return self>=value. """
pass def __gt__(self, *args, **kwargs):
""" Return self>value. """
pass def __hash__(self, *args, **kwargs):
""" Return hash(self). """
pass def __index__(self, *args, **kwargs):
""" Return self converted to an integer, if self is suitable for use as an index into a list. """
pass def __init__(self, x, base=10): # known special case of int.__init__
"""
int(x=0) -> integer
int(x, base=10) -> integer Convert a number or string to an integer, or return 0 if no arguments
are given. If x is a number, return x.__int__(). For floating point
numbers, this truncates towards zero. If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base. The literal can be preceded by '+' or '-' and be surrounded
by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0)
4
# (copied from class doc)
"""
pass def __int__(self, *args, **kwargs):
""" int(self) """
pass def __invert__(self, *args, **kwargs):
""" ~self """
pass def __le__(self, *args, **kwargs):
""" Return self<=value. """
pass def __lshift__(self, *args, **kwargs):
""" Return self<<value. """
pass def __lt__(self, *args, **kwargs):
""" Return self<value. """
pass def __mod__(self, *args, **kwargs):
""" Return self%value. """
pass def __mul__(self, *args, **kwargs):
""" Return self*value. """
pass def __neg__(self, *args, **kwargs):
""" -self """
pass @staticmethod # known case of __new__
def __new__(*args, **kwargs):
""" Create and return a new object. See help(type) for accurate signature. """
pass def __ne__(self, *args, **kwargs):
""" Return self!=value. """
pass def __or__(self, *args, **kwargs):
""" Return self|value. """
pass def __pos__(self, *args, **kwargs):
""" +self """
pass def __pow__(self, *args, **kwargs):
""" Return pow(self, value, mod). """
pass def __radd__(self, *args, **kwargs):
""" Return value+self. """
pass def __rand__(self, *args, **kwargs):
""" Return value&self. """
pass def __rdivmod__(self, *args, **kwargs):
""" Return divmod(value, self). """
pass def __repr__(self, *args, **kwargs):
""" Return repr(self). """
pass def __rfloordiv__(self, *args, **kwargs):
""" Return value//self. """
pass def __rlshift__(self, *args, **kwargs):
""" Return value<<self. """
pass def __rmod__(self, *args, **kwargs):
""" Return value%self. """
pass def __rmul__(self, *args, **kwargs):
""" Return value*self. """
pass def __ror__(self, *args, **kwargs):
""" Return value|self. """
pass def __round__(self, *args, **kwargs):
"""
Rounding an Integral returns itself.
Rounding with an ndigits argument also returns an integer.
"""
pass def __rpow__(self, *args, **kwargs):
""" Return pow(value, self, mod). """
pass def __rrshift__(self, *args, **kwargs):
""" Return value>>self. """
pass def __rshift__(self, *args, **kwargs):
""" Return self>>value. """
pass def __rsub__(self, *args, **kwargs):
""" Return value-self. """
pass def __rtruediv__(self, *args, **kwargs):
""" Return value/self. """
pass def __rxor__(self, *args, **kwargs):
""" Return value^self. """
pass def __sizeof__(self, *args, **kwargs):
""" Returns size in memory, in bytes """
pass def __str__(self, *args, **kwargs):
""" Return str(self). """
pass def __sub__(self, *args, **kwargs):
""" Return self-value. """
pass def __truediv__(self, *args, **kwargs):
""" Return self/value. """
pass def __trunc__(self, *args, **kwargs):
""" Truncating an Integral returns itself. """
pass def __xor__(self, *args, **kwargs):
""" Return self^value. """
pass denominator = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
"""the denominator of a rational number in lowest terms""" imag = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
"""the imaginary part of a complex number""" numerator = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
"""the numerator of a rational number in lowest terms""" real = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
"""the real part of a complex number"""

Python基本数据类型之int的更多相关文章

  1. Python基础数据类型之int、bool、str

    数据类型:int  bool  str  list  元祖  dict  集合 int:整数型,用于各种数学运算. bool:只有两种,True和False,用户判断. str:存储少量数据,进行操作 ...

  2. 8、Python简单数据类型(int、float、complex、bool、str)

    一.数据类型分类 1.按存值个数区分 单个值:数字,字符串 多个值(容器):列表,元组,字典,集合 2.按可变不可变区分 可变:列表[],字典{},集合{} 不可变:数字,字符串,元组().bool, ...

  3. Python基本数据类型之int 、 float

    首先要明确的是:在python中,一切皆为对象. 从底层角度看,对象就是保存在内存中的一个数据块.从抽象层看,对象就是我们的代码模拟出的一个类的独立个体. 在python中变量不需要声明类型,也不需要 ...

  4. python基本数据类型,int,bool,str

    一丶python基本数据类型 1.int 整数,主要用来进行数学运算. 2.str 字符串,可以保存少量数据并进行相应的操作 3.bool 判断真假.True.False 4.list 存储大量数据, ...

  5. python学习之数据类型(int,bool,str)

    第三章 数据类型 3.1 Python基本数据类型 类型 含义 描述 int 整数 主要用来进⾏数学运算 str 字符串 可以保存少量数据并进⾏相应的操作 bool 布尔值 判断真假,True,Fal ...

  6. python中的基本数据类型之 int bool str

    一.基本数据类型 1. int  ==>  整数.主要用来进行数学运算. 2.str  ==>  字符串.可以保存少量的数据,并进行相应的操作. 3.bool  =>  布尔值.判断 ...

  7. python 基本数据类型分析

    在python中,一切都是对象!对象由类创建而来,对象所拥有的功能都来自于类.在本节中,我们了解一下python基本数据类型对象具有哪些功能,我们平常是怎么使用的. 对于python,一切事物都是对象 ...

  8. python常用数据类型内置方法介绍

    熟练掌握python常用数据类型内置方法是每个初学者必须具备的内功. 下面介绍了python常用的集中数据类型及其方法,点开源代码,其中对主要方法都进行了中文注释. 一.整型 a = 100 a.xx ...

  9. python自学笔记(二)python基本数据类型之字符串处理

    一.数据类型的组成分3部分:身份.类型.值 身份:id方法来看它的唯一标识符,内存地址靠这个查看 类型:type方法查看 值:数据项 二.常用基本数据类型 int 整型 boolean 布尔型 str ...

随机推荐

  1. 特殊约束From To

    说实话这个不太懂,没用过也没有遇到相应的情况(或者说我不知道).大家可以更多的去参考特定约束FROM TO和MicroZed开发板笔记,第72部分:多周期约束等内容. 本文待修正 系列目录      ...

  2. React Native 在现有项目中的探路

    移动开发中,native开发性能和效果上无疑是最好的. 但是在众多的情况下,native开发并不是最优的选择.当需求经常改动的时候,当预算有限的时候,当deadline很近的时候,native开发的成 ...

  3. AMDJS编译工具

    amdjs-build可以将amdjs标准的js代码编译成原生的js代码,从而在发布时去除多余的模块加载器代码. 比如像这样的代码: define("a/b", ["b& ...

  4. CSS HACK tab制表符导致行内元素之间的空隙如何解决

    <!DOCTYPE html> <html lang="zh-CN"><head> <meta name="viewport&q ...

  5. LINUX 配置SVN

    1. 安装SVN  yum -y install subversion 2. 创建版本库目录  mkdir /root/svn/ svnserve -d -r /root/svn/ 3. 创建版本库 ...

  6. springMVC之AOP

    AOP(Aspect-Oriented Programming,面向切面编程) 切面(Aepect):横切关注点(跨越应用程序多个模块的功能)被模块化的对象: 通知(Advice):切面必须要完成的工 ...

  7. openwrt的环境搭建、定制和编译

    参考1:编译openwrt全过程 参考2: ARM9的OpenWRT系统的移植以及 无线视觉操控系统的软件开发 参考3:搭建OpenWrt开发环境(包括编译过程) 参考4:各个openwrt版本的sv ...

  8. iOS开发--二维码的扫描

    一.需要包含头文件 #import <AVFoundation/AVFoundation.h> 二.通过设置<AVCaptureMetadataOutputObjectsDelega ...

  9. 【BZOJ 3052】【WC 2013】糖果公园

    对树的dfs序分块,打开了新世界的大门233 第一关键字是l所在的块,第二关键字是r所在的块,第三关键字是时间,分完块后暴力莫队即可 #include<cmath> #include< ...

  10. git之旅【第二篇】

    1,git的安装 最早Git是在Linux上开发的,很长一段时间内,Git也只能在Linux和Unix系统上跑.不过,慢慢地有人把它移植到了Windows上.现在,Git可以在Linux.Unix.M ...