class float([n])
The float function returns a real number from a number or a text string.
If the argument is a text string, it should contain the decimal point (though not required, see example below), optionally preceded by a sign. If no argument is added, the function returns the real number 0.0. The argument can also be a text string representing a "nan" (not a number) or a positive or negative infinity. More exactly, the argument must comply with the following grammar after removing whitespaces at the beginning and end of the string:
sign :: = "+" | "-"
infinite :: = "Infinity" | "inf"
nan :: = "nan"
numeric_value :: = real_number | infinity | nan
text_string :: = [sign] numeric_value
- n: (optional) number or text string to convert to real number.
The function can convert whole numbers to their real equivalent format. The possible + sign before the number is not required:
The argument can also be a real number:
If the argument is a text string, it can include the decimal point or not:
If it is a whole number, you can include the decimal separator but not include the decimal part:
The text string may or may not include the sign:
The text string can include blank spaces at the beginning or end of it, spaces that are not considered in the conversion:
The number represented in the text string can be in scientific notation:
The argument can represent the "nan" value (not a number):
It can also represent infinity, both positive and negative:
If no argument is included, the function returns zero:
print(float())