0
Understanding string and float. (Need help) Python
Could anyone help me sorting this? If I have the following: 5 * float(“2”) I will have as result 22.0, right? In that case how can I identify if the code is using a float number or a string between “?
3 Réponses
+ 13
No the result will be 10.0 because you first transformed "2" (which is a string) into a float and then you multiplied by an integer and that gives you a float :10.0 (as long as you have a float somewhere in any operation the result will be a float unless you specify otherwise (using int() etc.)). There is an exception:
10/5 will be a float even though both 10 and 5 are int because the / (true division) will always return a float
+ 5
You're welcome Victor Biscio I'm glad I could help ; )
+ 1
Uni got it! thank you so much for your explanation!