0

Why 3/6 is 0 and 3/6.0 is 0.5 which is a float?

I understand that python automatically convert interger into float. why in the first case it's showing 0.

9th Jul 2018, 4:26 PM
ved bhardwaj
ved bhardwaj - avatar
5 Answers
+ 2
I think you are using python 2 version please use latest version of python. In version 3 , 3/6=0.5 and 0.5 is float.
9th Jul 2018, 4:31 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
Maninder Singh yes I think I am . thanks for pointing out the issue.
9th Jul 2018, 4:33 PM
ved bhardwaj
ved bhardwaj - avatar
0
If you divide an integer by another integer, the compiler assumes you are doing integer arithmetic, and therefore the result will be an integer too, in this case 0 because 6 doesn't fit in 3.
9th Jul 2018, 4:30 PM
Shadow
Shadow - avatar
0
does it mean interger operation always return an integer?
9th Jul 2018, 4:31 PM
ved bhardwaj
ved bhardwaj - avatar
0
Use python latest version 3.6
11th Jul 2018, 7:46 AM
Bhavya Pawar
Bhavya Pawar - avatar