float数据类型

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

    下面来看一看float数据类型都有那些经常使用的操做,以及和int不同的地方:ide

    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
ui

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

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

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

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

    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
ci

    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

相关文章
相关标签/搜索