Operations | Sololearn: Learn to code for FREE!



Why do i get float if i divide in operations?Python

11/18/2018 5:38:41 PM


5 Answers

New Answer


Hello, 😊 Can you specifying your question correctly! Use the search bar! https://www.sololearn.com/post/10362/?ref=app Please, read our guidelines: https://www.sololearn.com/discuss/1316935/?ref=app An useful code for any new user here!;) https://code.sololearn.com/WvG0MJq2dQ6y/


Which language is that?


Thank you




If you divide 3 by 2, you get 1.5, right? If the result doesn't become a float, 3/2 would become 1 instead and the 0.5 is lost. In other languages like C this is actually the case: If you don't specifically say otherwise and you divide one int by another, the decimals disappear. Python is just designed the other way round: It creates a float whenever you divide, 'to be on the safe side'. If in Python you specifically don't want the decimals, you can use //.