float :: Class float
[hide private]
[frames] | no frames]

Class float


float(x) -> floating point number

Convert a string or number to a floating point number, if possible.

Instance Methods [hide private]
 
__abs__(x)
x.__abs__() <==> abs(x)
 
__add__(x, y)
x.__add__(y) <==> x+y
 
__coerce__(x, y)
x.__coerce__(y) <==> coerce(x, y)
 
__div__(x, y)
x.__div__(y) <==> x/y
 
__divmod__(x, y)
x.__divmod__(y) <==> divmod(x, y)
 
__eq__(x, y)
x.__eq__(y) <==> x==y
 
__float__(x)
x.__float__() <==> float(x)
 
__floordiv__(x, y)
x.__floordiv__(y) <==> x//y
string
__format__(float, format_spec)
float.__format__(format_spec) -> string
 
__ge__(x, y)
x.__ge__(y) <==> x>=y
 
__getattribute__(...)
x.__getattribute__('name') <==> x.name
string
__getformat__(float, typestr)
float.__getformat__(typestr) -> string
 
__getnewargs__(...)
 
__gt__(x, y)
x.__gt__(y) <==> x>y
 
__hash__(x)
x.__hash__() <==> hash(x)
 
__int__(x)
x.__int__() <==> int(x)
 
__le__(x, y)
x.__le__(y) <==> x<=y
 
__long__(x)
x.__long__() <==> long(x)
 
__lt__(x, y)
x.__lt__(y) <==> x<y
 
__mod__(x, y)
x.__mod__(y) <==> x%y
 
__mul__(x, y)
x.__mul__(y) <==> x*y
 
__ne__(x, y)
x.__ne__(y) <==> x!=y
 
__neg__(x)
x.__neg__() <==> -x
a new object with type S, a subtype of T
__new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
 
__nonzero__(x)
x.__nonzero__() <==> x != 0
 
__pos__(x)
x.__pos__() <==> +x
 
__pow__(x, y, z=...)
x.__pow__(y[, z]) <==> pow(x, y[, z])
 
__radd__(x, y)
x.__radd__(y) <==> y+x
 
__rdiv__(x, y)
x.__rdiv__(y) <==> y/x
 
__rdivmod__(x, y)
x.__rdivmod__(y) <==> divmod(y, x)
 
__repr__(x)
x.__repr__() <==> repr(x)
 
__rfloordiv__(x, y)
x.__rfloordiv__(y) <==> y//x
 
__rmod__(x, y)
x.__rmod__(y) <==> y%x
 
__rmul__(x, y)
x.__rmul__(y) <==> y*x
 
__rpow__(y, x, z=...)
y.__rpow__(x[, z]) <==> pow(x, y[, z])
 
__rsub__(x, y)
x.__rsub__(y) <==> y-x
 
__rtruediv__(x, y)
x.__rtruediv__(y) <==> y/x
None
__setformat__(float, typestr, fmt)
float.__setformat__(typestr, fmt) -> None
 
__str__(x)
x.__str__() <==> str(x)
 
__sub__(x, y)
x.__sub__(y) <==> x-y
 
__truediv__(x, y)
x.__truediv__(y) <==> x/y
 
__trunc__(...)
Returns the Integral closest to x between 0 and x.
(int, int)
as_integer_ratio(float)
float.as_integer_ratio() -> (int, int)
 
conjugate(...)
Returns self, the complex conjugate of any float.
float
fromhex(float, string)
float.fromhex(string) -> float
string
hex(float)
float.hex() -> string
 
is_integer(...)
Returns True if the float is an integer.

Inherited from object: __delattr__, __init__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]
  imag
the imaginary part of a complex number
  real
the real part of a complex number

Inherited from object: __class__

Method Details [hide private]

__format__(float, format_spec)

 

float.__format__(format_spec) -> string

Formats the float according to format_spec.

Returns: string
Overrides: object.__format__

__getattribute__(...)

 
x.__getattribute__('name') <==> x.name
Overrides: object.__getattribute__

__getformat__(float, typestr)

 

float.__getformat__(typestr) -> string

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'. This function returns whichever of 'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the format of floating point numbers used by the C type named by typestr.

Returns: string

__hash__(x)
(Hashing function)

 
x.__hash__() <==> hash(x)
Overrides: object.__hash__

__new__(T, S, ...)

 
T.__new__(S, ...) -> a new object with type S, a subtype of T
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__repr__(x)
(Representation operator)

 
x.__repr__() <==> repr(x)
Overrides: object.__repr__

__setformat__(float, typestr, fmt)

 

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.

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

Returns: None

__str__(x)
(Informal representation operator)

 
x.__str__() <==> str(x)
Overrides: object.__str__

as_integer_ratio(float)

 

float.as_integer_ratio() -> (int, int)

Returns a pair of integers, whose ratio is exactly equal to the original float and with a positive denominator. Raises 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)
Returns: (int, int)

fromhex(float, string)

 

float.fromhex(string) -> float

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

Returns: float

hex(float)

 

float.hex() -> string

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

Returns: string