The float()
function is used to convert a given value into a floating-point number (a number with a decimal point) of type float.
The function can also be called without any argument in which case it returns 0.0
float(x = None)
copy
x |
The value to be casted to a floating type value. It is optional |
The function returns the floating point representation of x
.If x is not given it returns 0.0
Passing a value which is not representable as a float raises a ValueError
. The value passed also needs to be of supported type, such as integer, string or a user defined object that defines the __float__
method, otherwise a TypeError
is raised. Examples: