0

Why should I use a float?

I mean what's the difference if I type print float(5+1) and print int(5+1) ??

8th Jul 2017, 11:34 PM
Captain George
Captain George - avatar
3 Answers
+ 3
The Python course goes over this. float's are decimal numbers. print(float(5+1)) Will print 6.0 int's are whole numbers. print(int(5+1)) Will print 6 float(#something ) Will convert (cast) the something to type float.
8th Jul 2017, 11:41 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
Well, a float is more useful when you have a different example like 1.5 +5.0 and that is 6.5 maybe you have been thinking on this. But It depends if that result can be affected like for example if it is a banking account imagine that you have $6.00 obviously you care about the floats. Another example could be a university grade you care if it is a 6.45 or a 7.00 Regards :)
9th Jul 2017, 6:27 AM
María José
María José - avatar