The Python float()
is a built-in function that returns a floating point number constructed from a number or a string.
float(arg)
Where,
If the argument is a string, it should contain a decimal number, optionally preceded by a sign( + or – ), and optionally embedded in whitespace.
The Python float()
function returns:
0.0
if no argument is passedOverflowError
if outside the range of floating point numberWell, Python has built-in function type()
which returns the type of object or simply the class to which the object belongs to.
>>> type(1)
<class 'int'>
>>> x = float(1)
>>> type(x)
<class 'float'>
>>> #integer
>>> float(1)
1.0
>>> #strings
>>> float('1')
1.0
>>> float('infinity')
inf
>>> float(1e-0.02)
0.01
>>> float(+2E3)
2000.0