Sololearn: Learn to Code
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
21st Dec 2016, 12:29 PM
Barracoder
Barracoder - avatar
+ 12
python 3 performs integer division meaning operands are implicitly converted to type float during division hence the result is a float
21st Dec 2016, 12:29 PM
Barracoder
Barracoder - avatar
+ 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.
21st Dec 2016, 12:30 PM
Majstor_Gile
Majstor_Gile - avatar
+ 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.
7th Jan 2017, 12:56 PM
Tarun Kumar Singh
Tarun Kumar Singh - avatar