Python之整数类型

整数:18,73,84

每一个整数都有如下的功能:class int(object):

"""
    int(x=0) -> int or long
    int(x, base=10) -> int or long

    Convert a number or string to an integer, or return 0 if no arguments
    are given.  If x is floating point, the conversion truncates towards zero.
    If x is outside the integer range, the function returns a long instead.

    If x is not a number or if base is given, then x must be a string or
    Unicode object 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)
    """
    def bit_length(self):
        """ 返回表示该数字的时占用的最少位数 """
        """
        int.bit_length() -> int

        Number of bits necessary to represent self in binary.
        >>> bin(37)
        ‘0b100101‘
        >>> (37).bit_length()
        """
        return 0

    def conjugate(self, *args, **kwargs): # real signature unknown
        """ 返回该复数的共轭复数 """
        """ Returns self, the complex conjugate of any int. """
        pass

    def __abs__(self):
        """ 返回绝对值 """
        """ x.__abs__() <==> abs(x) """
        pass

    def __add__(self, y):
        """ x.__add__(y) <==> x+y """
        pass

    def __and__(self, y):
        """ x.__and__(y) <==> x&y """
        pass

    def __cmp__(self, y):
        """ 比较两个数大小 """
        """ x.__cmp__(y) <==> cmp(x,y) """
        pass

    def __coerce__(self, y):
        """ 强制生成一个元组 """
        """ x.__coerce__(y) <==> coerce(x, y) """
        pass

    def __divmod__(self, y):
        """ 相除,得到商和余数组成的元组 """
        """ x.__divmod__(y) <==> divmod(x, y) """
        pass

    def __div__(self, y):
        """ x.__div__(y) <==> x/y """
        pass

    def __float__(self):
        """ 转换为浮点类型 """
        """ x.__float__() <==> float(x) """
        pass

    def __floordiv__(self, y):
        """ x.__floordiv__(y) <==> x//y """
        pass

    def __format__(self, *args, **kwargs): # real signature unknown
        pass

    def __getattribute__(self, name):
        """ x.__getattribute__(‘name‘) <==> x.name """
        pass

    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        """ 内部调用 __new__方法或创建对象时传入参数使用 """
        pass

    def __hash__(self):
        """如果对象object为哈希表类型,返回对象object的哈希值。哈希值为整数。在字典查找中,哈希值用于快速比较字典的键。两个数值如果相等,则哈希值也相等。"""
        """ x.__hash__() <==> hash(x) """
        pass

    def __hex__(self):
        """ 返回当前数的 十六进制 表示 """
        """ x.__hex__() <==> hex(x) """
        pass

    def __index__(self):
        """ 用于切片,数字无意义 """
        """ x[y:z] <==> x[y.__index__():z.__index__()] """
        pass

    def __init__(self, x, base=10): # known special case of int.__init__
        """ 构造方法,执行 x = 123 或 x = int(10) 时,自动调用,暂时忽略 """
        """
        int(x=0) -> int or long
        int(x, base=10) -> int or long

        Convert a number or string to an integer, or return 0 if no arguments
        are given.  If x is floating point, the conversion truncates towards zero.
        If x is outside the integer range, the function returns a long instead.

        If x is not a number or if base is given, then x must be a string or
        Unicode object 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)
        # (copied from class doc)
        """
        pass

    def __int__(self):
        """ 转换为整数 """
        """ x.__int__() <==> int(x) """
        pass

    def __invert__(self):
        """ x.__invert__() <==> ~x """
        pass

    def __long__(self):
        """ 转换为长整数 """
        """ x.__long__() <==> long(x) """
        pass

    def __lshift__(self, y):
        """ x.__lshift__(y) <==> x<<y """
        pass

    def __mod__(self, y):
        """ x.__mod__(y) <==> x%y """
        pass

    def __mul__(self, y):
        """ x.__mul__(y) <==> x*y """
        pass

    def __neg__(self):
        """ x.__neg__() <==> -x """
        pass

    @staticmethod # known case of __new__
    def __new__(S, *more):
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass

    def __nonzero__(self):
        """ x.__nonzero__() <==> x != 0 """
        pass

    def __oct__(self):
        """ 返回改值的 八进制 表示 """
        """ x.__oct__() <==> oct(x) """
        pass

    def __or__(self, y):
        """ x.__or__(y) <==> x|y """
        pass

    def __pos__(self):
        """ x.__pos__() <==> +x """
        pass

    def __pow__(self, y, z=None):
        """ 幂,次方 """
        """ x.__pow__(y[, z]) <==> pow(x, y[, z]) """
        pass

    def __radd__(self, y):
        """ x.__radd__(y) <==> y+x """
        pass

    def __rand__(self, y):
        """ x.__rand__(y) <==> y&x """
        pass

    def __rdivmod__(self, y):
        """ x.__rdivmod__(y) <==> divmod(y, x) """
        pass

    def __rdiv__(self, y):
        """ x.__rdiv__(y) <==> y/x """
        pass

    def __repr__(self):
        """转化为解释器可读取的形式 """
        """ x.__repr__() <==> repr(x) """
        pass

    def __str__(self):
        """转换为人阅读的形式,如果没有适于人阅读的解释形式的话,则返回解释器课阅读的形式"""
        """ x.__str__() <==> str(x) """
        pass

    def __rfloordiv__(self, y):
        """ x.__rfloordiv__(y) <==> y//x """
        pass

    def __rlshift__(self, y):
        """ x.__rlshift__(y) <==> y<<x """
        pass

    def __rmod__(self, y):
        """ x.__rmod__(y) <==> y%x """
        pass

    def __rmul__(self, y):
        """ x.__rmul__(y) <==> y*x """
        pass

    def __ror__(self, y):
        """ x.__ror__(y) <==> y|x """
        pass

    def __rpow__(self, x, z=None):
        """ y.__rpow__(x[, z]) <==> pow(x, y[, z]) """
        pass

    def __rrshift__(self, y):
        """ x.__rrshift__(y) <==> y>>x """
        pass

    def __rshift__(self, y):
        """ x.__rshift__(y) <==> x>>y """
        pass

    def __rsub__(self, y):
        """ x.__rsub__(y) <==> y-x """
        pass

    def __rtruediv__(self, y):
        """ x.__rtruediv__(y) <==> y/x """
        pass

    def __rxor__(self, y):
        """ x.__rxor__(y) <==> y^x """
        pass

    def __sub__(self, y):
        """ x.__sub__(y) <==> x-y """
        pass

    def __truediv__(self, y):
        """ x.__truediv__(y) <==> x/y """
        pass

    def __trunc__(self, *args, **kwargs):
        """ 返回数值被截取为整形的值,在整形中无意义 """
        pass

    def __xor__(self, y):
        """ x.__xor__(y) <==> x^y """
        pass

    denominator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """ 分母 = 1 """
    """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"""

长整型:long int

可能如:2147483649、9223372036854775807

每个长整型都具备如下功能:

class long(object):
    """
    long(x=0) -> long
    long(x, base=10) -> long

    Convert a number or string to a long integer, or return 0L if no arguments
    are given.  If x is floating point, the conversion truncates towards zero.

    If x is not a number or if base is given, then x must be a string or
    Unicode object 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)
    4L
    """
    def bit_length(self): # real signature unknown; restored from __doc__
        """
        long.bit_length() -> int or long

        Number of bits necessary to represent self in binary.
        >>> bin(37L)
        ‘0b100101‘
        >>> (37L).bit_length()
        """
        return 0

    def conjugate(self, *args, **kwargs): # real signature unknown
        """ Returns self, the complex conjugate of any long. """
        pass

    def __abs__(self): # real signature unknown; restored from __doc__
        """ x.__abs__() <==> abs(x) """
        pass

    def __add__(self, y): # real signature unknown; restored from __doc__
        """ x.__add__(y) <==> x+y """
        pass

    def __and__(self, y): # real signature unknown; restored from __doc__
        """ x.__and__(y) <==> x&y """
        pass

    def __cmp__(self, y): # real signature unknown; restored from __doc__
        """ x.__cmp__(y) <==> cmp(x,y) """
        pass

    def __coerce__(self, y): # real signature unknown; restored from __doc__
        """ x.__coerce__(y) <==> coerce(x, y) """
        pass

    def __divmod__(self, y): # real signature unknown; restored from __doc__
        """ x.__divmod__(y) <==> divmod(x, y) """
        pass

    def __div__(self, y): # real signature unknown; restored from __doc__
        """ x.__div__(y) <==> x/y """
        pass

    def __float__(self): # real signature unknown; restored from __doc__
        """ x.__float__() <==> float(x) """
        pass

    def __floordiv__(self, y): # real signature unknown; restored from __doc__
        """ x.__floordiv__(y) <==> x//y """
        pass

    def __format__(self, *args, **kwargs): # real signature unknown
        pass

    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ x.__getattribute__(‘name‘) <==> x.name """
        pass

    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        pass

    def __hash__(self): # real signature unknown; restored from __doc__
        """ x.__hash__() <==> hash(x) """
        pass

    def __hex__(self): # real signature unknown; restored from __doc__
        """ x.__hex__() <==> hex(x) """
        pass

    def __index__(self): # real signature unknown; restored from __doc__
        """ x[y:z] <==> x[y.__index__():z.__index__()] """
        pass

    def __init__(self, x=0): # real signature unknown; restored from __doc__
        pass

    def __int__(self): # real signature unknown; restored from __doc__
        """ x.__int__() <==> int(x) """
        pass

    def __invert__(self): # real signature unknown; restored from __doc__
        """ x.__invert__() <==> ~x """
        pass

    def __long__(self): # real signature unknown; restored from __doc__
        """ x.__long__() <==> long(x) """
        pass

    def __lshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__lshift__(y) <==> x<<y """
        pass

    def __mod__(self, y): # real signature unknown; restored from __doc__
        """ x.__mod__(y) <==> x%y """
        pass

    def __mul__(self, y): # real signature unknown; restored from __doc__
        """ x.__mul__(y) <==> x*y """
        pass

    def __neg__(self): # real signature unknown; restored from __doc__
        """ x.__neg__() <==> -x """
        pass

    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass

    def __nonzero__(self): # real signature unknown; restored from __doc__
        """ x.__nonzero__() <==> x != 0 """
        pass

    def __oct__(self): # real signature unknown; restored from __doc__
        """ x.__oct__() <==> oct(x) """
        pass

    def __or__(self, y): # real signature unknown; restored from __doc__
        """ x.__or__(y) <==> x|y """
        pass

    def __pos__(self): # real signature unknown; restored from __doc__
        """ x.__pos__() <==> +x """
        pass

    def __pow__(self, y, z=None): # real signature unknown; restored from __doc__
        """ x.__pow__(y[, z]) <==> pow(x, y[, z]) """
        pass

    def __radd__(self, y): # real signature unknown; restored from __doc__
        """ x.__radd__(y) <==> y+x """
        pass

    def __rand__(self, y): # real signature unknown; restored from __doc__
        """ x.__rand__(y) <==> y&x """
        pass

    def __rdivmod__(self, y): # real signature unknown; restored from __doc__
        """ x.__rdivmod__(y) <==> divmod(y, x) """
        pass

    def __rdiv__(self, y): # real signature unknown; restored from __doc__
        """ x.__rdiv__(y) <==> y/x """
        pass

    def __repr__(self): # real signature unknown; restored from __doc__
        """ x.__repr__() <==> repr(x) """
        pass

    def __rfloordiv__(self, y): # real signature unknown; restored from __doc__
        """ x.__rfloordiv__(y) <==> y//x """
        pass

    def __rlshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__rlshift__(y) <==> y<<x """
        pass

    def __rmod__(self, y): # real signature unknown; restored from __doc__
        """ x.__rmod__(y) <==> y%x """
        pass

    def __rmul__(self, y): # real signature unknown; restored from __doc__
        """ x.__rmul__(y) <==> y*x """
        pass

    def __ror__(self, y): # real signature unknown; restored from __doc__
        """ x.__ror__(y) <==> y|x """
        pass

    def __rpow__(self, x, z=None): # real signature unknown; restored from __doc__
        """ y.__rpow__(x[, z]) <==> pow(x, y[, z]) """
        pass

    def __rrshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__rrshift__(y) <==> y>>x """
        pass

    def __rshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__rshift__(y) <==> x>>y """
        pass

    def __rsub__(self, y): # real signature unknown; restored from __doc__
        """ x.__rsub__(y) <==> y-x """
        pass

    def __rtruediv__(self, y): # real signature unknown; restored from __doc__
        """ x.__rtruediv__(y) <==> y/x """
        pass

    def __rxor__(self, y): # real signature unknown; restored from __doc__
        """ x.__rxor__(y) <==> y^x """
        pass

    def __sizeof__(self, *args, **kwargs): # real signature unknown
        """ Returns size in memory, in bytes """
        pass

    def __str__(self): # real signature unknown; restored from __doc__
        """ x.__str__() <==> str(x) """
        pass

    def __sub__(self, y): # real signature unknown; restored from __doc__
        """ x.__sub__(y) <==> x-y """
        pass

    def __truediv__(self, y): # real signature unknown; restored from __doc__
        """ x.__truediv__(y) <==> x/y """
        pass

    def __trunc__(self, *args, **kwargs): # real signature unknown
        """ Truncating an Integral returns itself. """
        pass

    def __xor__(self, y): # real signature unknown; restored from __doc__
        """ x.__xor__(y) <==> x^y """
        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"""

long
 

原文地址:https://www.cnblogs.com/pythonlearing/p/9744952.html

时间: 2024-11-03 16:03:16

Python之整数类型的相关文章

Python的动态类型

动态类型:                                                      在python中,类型是在运行过程中自动决定的,而不是通过代码声明的. 变量:                                                                                     变量是一个系统表的元素,拥有指向对象的连接的空间 python中,类型的概念是存在于对象中的,而不是变量中,变量是通用的. 变量的使用

Python的数值类型

问题: 1. Python数值有哪些? 2. 各类型的精度是多少? 3. 类型的转换是如何实现的? 5. 如何使用这些数据类型?需要注意什么? 6. 什么是不可变类型? 数值类型:     整型: (不可变类型)         标准整型:取值范围[-sys.maxint-1, sys.maxint]         长整型:可表示无限大的整数,其值仅与你机器支持的(虚拟)内存大小有关         数值超出标准整型范围将会转换为长整型.         例如:             1.定

Python&lt;9&gt;动态类型简介

动态类型以及它提供的多态性,无疑是Python语言简洁性和灵活性的基础. 一.变量 <1>变量创建 一个变量a,当代码第一次给它赋值时就创建了它,之后的赋值将会改变已创建的变量名的值. <2>变量类型 变量永远不会有任何的和它关联的类型信息或约束.变量原本是通用的,它只是在一个特定的时间点,简单的引用了 一下特定的对象而已. <3>变量使用 当变量出现在表达式中,它会马上被当前引用的对象所替代(对象是有类型的).此外所有的变量必须在使用前明确的 赋值,使用未赋值的变量会

十分钟学会Python的基本类型

一:起因 (1)说起学习Python的原因,上一篇blog已经提到过了:Python掐指一算不过是自己接触过的第四门大型语言(从接触到现在已经2周了)c/c++ ,Java,MATLAB(PS:应该还不算入门,只会简单的应用),之后就是python了. (2)c/c++ 到java的过渡是非常短暂的,但是过渡到MATLA就非常的不顺利(PS:就是上一篇的blog提到过的,从内心里抵触一门未曾谋面的语言),当时就已经感受到了开启一门新语言阻力非常大(有时可以用可遇不可求来形容). (3)从java

怒学Python——第二篇——类型与运算

Python支持5种数据类型,包括数字(numbers).字符串(string).列表(list).元组(tuple)和字典(dictionary).作为一门动态类型语言,不用去声明一个标示符的类型,使用的时候是什么类型会自动判定. 对于定义好的变量,若不使用该变量,可以用del删除来释放占有的资源,如 var = 10 del var Python的数字(numbers):支持int.long.float和complex,比较简单不给出示例. Python的字符串(string):如前面所说的

Python的文件类型和字符串

1. Python的文件类型 1. 源代码--直接由Python解析 vi 1.py #!/usr/bin/python print 'hello world' 这里的1.py就是源代码 执行方式和shell脚本类似: chmod +x 后,./1.py Python 1.py 2. 字节代码 Python源码文件经编译后生成的扩展名为pyc的文件 编译方法: [[email protected] py]# cat 2.py #!/usr/bin/python import py_compile

python的文件类型

1.3.1 源代码python源代码以".py"为扩展名,由python程序解释,不需要编译 1.3.2 字节代码python源码文件经过编译后生成的扩展名为".pyc"的文件,提供模块的编译方法为import py_compilepy_compile.compile("hello.py")比如我们新建一个"1.py"的文件,代码如下: #!/usr/bin/python print("Hello World !&q

别再说Python没有枚举类型了,好好看看

枚举类型可以看作是一种标签或是一系列常量的集合,通常用于表示某些特定的有限集合,例如星期.月份.状态等. Python 的原生类型(Built-in types)里并没有专门的枚举类型,但是我们可以通过很多方法来实现它,例如字典.类等: MiracleLove = {'MON': '林志玲', 'TUS': '陈意涵', 'WEN': '张柏芝', 'THU': '辛芷蕾', 'FRI': '周冬雨'} class MiracleLove: MON = '林志玲' TUS = '陈意涵' WEN

Python的数字类型

python数字类型有三种: 整数类型.浮点数类型.复数类型. 一.整数类型 示例: 十进制:1010 , 99 , -217 十六进制:0x9a , 0X89 ( 0x , 0X 开头表示十六进制) 二进制:0b010,-0B101 ( 0b , 0B 开头表示二进制 ) 八进制:0o123 , -0O456 ( 0o , 0O 开头是八进制 ) 二.浮点数类型 带有小数点和小数的数字 python中的浮点数的数值范围和小数精度都存在限制,这种限制与在不同的计算机系统有关. 示例: 0.0 ,