一、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. 为 Xamarin.Forms 做个跑马灯控件

    前段时间,私下用 Xamarin.Forms 做了个商业项目的演示版.很多被国内App玩坏了的控件/效果,XF上都没有或是找不到对应的实现,没有办法只能亲自上阵写了几个,效果还行,就是有BUG. 这个 ...

  2. parsing XML document from class path resource

    遇到问题:parsing XML document from class path resource [spring/resources] 解决方法:项目properties— source—remo ...

  3. jQuery操作单选按钮(radio)用法

    1.获取选中值,四种方法都可以: $('input:radio:checked').val():$("input[type='radio']:checked").val(); $( ...

  4. jni的使用方法

    我们可以通过jni来调用c/c++程序,C/C++一般会被作为动态库的形式来供java程序调用 环境 操作系统:Centos6.7 java: openjdk7 依赖包:java7-devel(yum ...

  5. [转]7个高性能JavaScript代码高亮插件

    对于喜欢写技术博客的同学来说,一定对代码高亮组件非常熟悉.一款优秀的JavaScript代码高亮插件,将会帮助你渲染任何一种编程语言,包括一些关键字的着色,以及每行代码的缩进等.今天我们要来分享一些高 ...

  6. mysql性能优化-慢查询分析、优化索引和配置

    一.优化概述 二.查询与索引优化分析 1性能瓶颈定位 Show命令 慢查询日志 explain分析查询 profiling分析查询 2索引及查询优化 三.配置优化 1)      max_connec ...

  7. 简单的解释XSS攻击

    XSS 跨站点脚本 cross site script 怎么造成攻击? 举例:有一个公共的页面,所有用户都可以访问且可以保存内容,输入的时候若输入<script>alert('I am h ...

  8. linux 常用命令总结

    PS命令: 1.命令格式: ps[参数] 2.命令功能: 用来显示当前进程的状态 3.命令参数: a  显示所有进程 -a 显示同一终端下的所有程序 -A 显示所有进程 c  显示进程的真实名称 -N ...

  9. 作业4-两人编程<词频统计>

     协作:苗中峰,刘鑫成       我主要攻克排序,成哥写了文件流的使用.整合工作由我完成,成哥帮我查阅资料,避免和解决语法错误.              这次任务较作业三的变化是:       * ...

  10. Code.R团队展示

    团队成员: 031302620马凛凛(队长) 031302619吕昆明 031302319汪毓顺 031302404陈俊达 团队名称: Code.R 团队项目: 基于web的教师报课系统 团队成员风采 ...