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.

float(value) 

Python float() function example

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

# for integers
print(float(10))

# for floats
print(float(10.20))

# for string floats
print(float("-10.30"))

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

# string float error
print(float("Hello"))

Output:

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

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading