The float()
method in Python produces a floating-point number from a string or an integer.
This method is declared as follows:
The float()
method takes only one parameter, which is optional. This parameter can be a string or an integer.
The return value is a floating-point number. If a string needs to be passed in the float()
method, it must constitute all numeric characters in it. In the case of no parameter, it returns 0.
In the example below, for integers and strings with numeric characters, the float()
method returns floating-point numbers. With non-numeric strings, this method raises an error.
#No parameterprint (float())# Integerprint (float(10))# Stringprint(float("13.33"))# String with numeric characters and no decimal pointprint(float("17"))