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

 

 

 

 

 

   

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM