0

How can I convert string to float? in python.

I want to take an input which is may be a float.

8th Oct 2020, 12:21 PM
Nafis Sadiq Bhuyan
Nafis Sadiq Bhuyan - avatar
2 Respostas
+ 3
Since inputs are by default string type, you can easily cast them to float like this. num = float(input())
8th Oct 2020, 12:24 PM
Avinesh
Avinesh - avatar
0
x = input() if isinstance(x, float): x = float(x)
8th Oct 2020, 12:25 PM
Jnn
Jnn - avatar