Convert String to Float in Python

  • Post category:String

In Python, you can use a float() function to convert a string to float. In the below code, we will convert a string to a float. The float() function takes only one argument. The argument is the string to be converted.

Step 1: Create a string

Python

Step 2: Convert string to float

Python

Output:

str =  123.45
str type =  <class 'str'>
str =  123.45
str type =  <class 'float'>

Free resources to learn advanced skills: AiHints and CodeAllow