+ 1
Why is print(4+8)/2)=6.0 and not just 6
Please I need an explanation for this
4 Antworten
+ 3
Hi! because the division operation converts the type from an integer (int) to a floating point number (float)
lesson 4.1 python course
+ 3
python automatically converts division results as floats. if you wanted the results to be 6 instead of 6.0 you could use the floor divison operator ((4+8)//2) or convert the result to an integer with int((4+8)/2). however, both of these will drop any remainders.
+ 1
In python , '/' division operator always returns a float irrespective of whether the operands are int or float. If you need an int output, please use '//' (integer division) operator