Skip to content

Python float() function

  • by

Python float() function is used to convert the specified value into a floating point number. This function returns a floating point number from a number or a string.


Python float() function example

A simple example code shows the working of float().

# for integers

# for floats

# for string floats

# for string floats with whitespaces
print(float(" -20.45\n"))

# string float error


Python float() function

Do comment if you have any doubts or suggestions on this Python basic function tutorial.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *