New course! Every coder should learn Generative AI!
Try a free lesson+ 12
python 3 performs integer division meaning operands are implicitly converted to type float during division hence the result is a float
+ 12
python 3 performs integer division meaning operands are implicitly converted to type float during division hence the result is a float
+ 4
In pyhon3 there is two types of division.
Division 12/2 and floor division 12//2.
Regular division (/) always gives result with decimal number after dot (real numbers), which was not case in older python2.
+ 2
Python does an implicit typecasting during division and converts the result into float.
you may argue that 12 is perfectly divisible by 2, hence type casting is not required and you are quite correct. The advantage here is that interpreter doesn't has to do comparisons on the result to identify if it should store it as an integer or float. It every time stores the result as float to decrease execution time.