ExampleEdit & Run
#Use the float() Function

print(float(7))
print(float("10.6"))
copy
Output:
7.0 10.6 [Finished in 0.011116286739706993s]

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

Syntax:
float(x = None)
copy
x The value to be casted to a floating type value. It is optional
Parameters:

The function returns the floating point representation of .If x is not given it returns 0.0

ExampleEdit & Run
print( float() ) 

print( float(2.2) )

print( float(0) )

print( float(5) )

print( float("8.5") )

print( float("100.00") )
copy
Output:
0.0 2.2 0.0 5.0 8.5 100.0 [Finished in 0.009833966381847858s]

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:

ExampleEdit & Run
float("100.0.0") #error

float("Hello") #error

float([1, 2]) # error

float({2}) #error
copy
Output:
Traceback (most recent call last):   File "<string>", line 1, in <module> ValueError: could not convert string to float: '100.0.0' [Finished in 0.015072895213961601s]