+ 1

Why is print(4+8)/2)=6.0 and not just 6

Please I need an explanation for this

27th Mar 2021, 10:33 PM
Mugenyi Curtis Davis
Mugenyi Curtis Davis - avatar
4 Answers
+ 3
Hi! because the division operation converts the type from an integer (int) to a floating point number (float) lesson 4.1 python course
27th Mar 2021, 10:40 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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.
28th Mar 2021, 2:15 AM
you are smart. you are brave.
you are smart. you are brave. - avatar
+ 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
28th Mar 2021, 2:55 PM
Sharad