If python automatically swaps an integer to a float why does the .0 matter in 5.0 ? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

If python automatically swaps an integer to a float why does the .0 matter in 5.0 ?

e.g: 5.0 + 6 = 11.0 where .0 from 11.0 has no use or even needed and .0 doesn't give any valuable format too

11th May 2019, 9:06 AM
Just-for-Fun
Just-for-Fun - avatar
1 Réponse
+ 5
It's because the result of any mathematical operation that involves at least one float is always a float. It's easier to remember this rule than having to determine that a/b results in an int if a=10 and b=2, but in a float if b=3 etc.
11th May 2019, 9:40 AM
Anna
Anna - avatar