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) abs(x) |
__add__(x, y) x+y |
__coerce__(x, y) coerce(x, y) |
__div__(x, y) x/y |
__divmod__(x, y) divmod(x, y) |
__eq__(x, y) x==y |
__float__(x) float(x) |
__floordiv__(x, y) x//y |
string |
__format__(float, format_spec) Formats the float according to format_spec. |
__ge__(x, y) x>=y |
__getattribute__(...) x.__getattribute__('name') <==> x.name |
string |
__getformat__(float, typestr) You probably don't want to use this function. |
__getnewargs__(...) |
__gt__(x, y) x>y |
__hash__(x) hash(x) |
__int__(x) int(x) |
__le__(x, y) x<=y |
__long__(x) long(x) |
__lt__(x, y) x<y |
__mod__(x, y) x%y |
__mul__(x, y) x*y |
__ne__(x, y) x!=y |
__neg__(x) -x |
a new object with type S, a subtype of T |
__new__(T, S, ...) |
__nonzero__(x) x != 0 |
__pos__(x) +x |
__pow__(x, y, z=...) pow(x, y[, z]) |
__radd__(x, y) y+x |
__rdiv__(x, y) y/x |
__rdivmod__(x, y) divmod(y, x) |
__repr__(x) repr(x) |
__rfloordiv__(x, y) y//x |
__rmod__(x, y) y%x |
__rmul__(x, y) y*x |
__rpow__(y, x, z=...) pow(x, y[, z]) |
__rsub__(x, y) y-x |
__rtruediv__(x, y) y/x |
None |
__setformat__(float, typestr, fmt) You probably don't want to use this function. |
__str__(x) str(x) |
__sub__(x, y) x-y |
__truediv__(x, y) x/y |
__trunc__(...) Return the Integral closest to x between 0 and x. |
(int, int) |
as_integer_ratio(float) Return a pair of integers, whose ratio is exactly equal to the original float and with a positive denominator. |
conjugate(...) Return self, the complex conjugate of any float. |
float |
fromhex(float, string) Create a floating-point number from a hexadecimal string. |
string |
hex(float) Return a hexadecimal representation of a floating-point number. |
is_integer(...) Return 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) |
Formats the float according to format_spec. Returns: string Overrides: object.__format__

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

### __getformat__(float, typestr) |
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) |
hash(x) Overrides: object.__hash__

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

### __repr__(x) (Representation operator) |
repr(x) Overrides: object.__repr__

### __setformat__(float, typestr, fmt) |
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. Returns: None

### __str__(x) (Informal representation operator) |
str(x) Overrides: object.__str__

### as_integer_ratio(float) |
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)
Returns: (int, int)

### fromhex(float, string) |
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) |
Return a hexadecimal representation of a floating-point number. >>> (-0.1).hex() '-0x1.999999999999ap-4' >>> 3.14159.hex() '0x1.921f9f01b866ep+1' Returns: string