0
Operations
Why do i get float if i divide in operations?Python
5 Respostas
+ 6
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/
+ 1
Which language is that?
+ 1
Thank you
0
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 //.