float数据类型

    学习一门语言都要打好基础,前面的知识可能看着无聊,但是很重要,能够让我们打好坚实的基础,一定要掌握int、float、long、字符串、列表、元组、集合、字典、函数和类的基础常用的操作。

    下面来看一看float数据类型都有那些常用的操作,以及和int不一样的地方:

    1.as_integer_ratio()

    def as_integer_ratio(self): # real signature unknown; restored from __doc__
    """
    float.as_integer_ratio() -> (int, int)

        返回一个分数的最小表示整数表示显示,元组形式

    Return a pair of integers, whose ratio is exactly equal to the original
    float and with a positive denominator.
    Raise OverflowError on infinities and a ValueError on NaNs.

    >>> (10.0).as_integer_ratio()
    (10, 1)
    >>> (0.0).as_integer_ratio()
    (0, 1)
    >>> (-.25).as_integer_ratio()
    (-1, 4)
    """
    pass

    2.conjugate(self,*args,**kwargs)

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

    """conjugate()返回共轭复数,高中的时候我们都学习过,共轭复数"""
    pass

  3.fromhex(self,*args,**kwargs)

    def fromhex(self, string): # real signature unknown; restored from __doc__
    """
    float.fromhex(string) -> float

    Create a floating-point number from a hexadecimal string.
    >>> float.fromhex('0x1.ffffp10')
    2047.984375
    >>> float.fromhex('-0x1p-1074')
    -5e-324
    """
    return 0.0

    4.hex(self)

    def hex(self): # real signature unknown; restored from __doc__
    """
    float.hex() -> string

    Return a hexadecimal representation of a floating-point number.
    >>> (-0.1).hex()
    '-0x1.999999999999ap-4'
    >>> 3.14159.hex()
    '0x1.921f9f01b866ep+1'
    """
    return ""

  5.is_integer(self,*args,**kwargs)

    def is_integer(self, *args, **kwargs): # real signature unknown
    """ Return True if the float is an integer. """

        """判断一个浮点型数据是否是整型的(即小数部分为零)"""
    pass

  实例如下:

    >>> a = 3.0
  >>> b = 5.9
  >>> a.is_integer()
  True
  >>> b.is_integer()
  False
    我们定义了两个数3.0和5.9,其中3.0是满足is_integer的,5.9不满足返回布尔值False.

    6.__abs__(self,*args,**kwargs)

    def __abs__(self, *args, **kwargs): # real signature unknown
    """ abs(self) """

        """返回一个数的绝对值"""
    pass

    实例如下:

    >>> a = -3.59
  >>> b = -3
  >>> a.__abs__()
  3.59
  >>> b.__abs__()
  3

  7.__add__(self,*args,**kwargs)

    def __add__(self, *args, **kwargs): # real signature unknown
    """ Return self+value. """

        """两个数相加"""
    pass

    8.__setformat__(self,typestr,fmt)

    def __setformat__(self, typestr, fmt): # real signature unknown; restored from __doc__
    """
    float.__setformat__(typestr, fmt) -> None

    You probably don't want to use this function. It exists mainly to be
    used in Python's test suite.

    typestr must be 'double' or 'float'. fmt must be one of 'unknown',
    'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be
    one of the latter two if it appears to match the underlying C reality.

    Override the automatic determination of C-level floating point type.
    This affects how floats are converted to and from binary strings.
    """
    pass

   

原文地址:https://www.cnblogs.com/gengcx/p/6748872.html