class float(x=0.0) |
Return a floating point number constructed from a number or string x. |
REMARKS |
* No prefix required - Core * If the argument is a string, it should contain a decimal number, optionally preceded by a sign, and optionally embedded in whitespace. The optional sign may be '+' or '-'; a '+' sign has no effect on the value produced. The argument may also be a string representing a NaN (not-a-number), or positive or negative infinity. More precisely, the input must conform to the floatvalue production rule in the following grammar, after leading and trailing whitespace characters are removed: * Here digit is a Unicode decimal digit (character in the Unicode general category Nd). Case is not significant, so, for example, "inf", "Inf", "INFINITY", and "iNfINity" are all acceptable spellings for positive infinity. * Otherwise, if the argument is an integer or a floating point number, a floating point number with the same value (within Python's floating point precision) is returned. If the argument is outside the range of a Python float, an OverflowError will be raised. * If no argument is given, 0.0 is returned. |
>>> float('+1.23')
1.23
>>> float(' -12345\n')
-12345
>>> float('1e-003')
0.001
>>> float('+1E6')
1000000
>>> float('-Infinity')
-inf
© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited Top