Skip to content

Convert string to float Python | Example code

  • by

Use float() function to convert String to float in Python. This function takes any data type and converts it into a floating-point number.


Example convert string to float Python

Simple example code just passes the string value into a float function.

s = "3.141"

# converting string to float
Float = float(s)



Convert string to float Python


  • The string should contain a float value else float() would return ValueError
  • If the number is outside the range of a floating variable it would return OverflowError
  • No value is passed as an argument it returns 0.0

Do comment if you have any doubts and suggestions on this Python string to float topic.

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 *