學習一門語言都要打好基礎,前面的知識可能看着無聊,可是很重要,可以讓咱們打好堅實的基礎,必定要掌握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()返回共軛複數,高中的時候咱們都學習過,共軛複數"""
passrest
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.0ci
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