+ 7
Why it giving output 0.0?
print(6/3%2*3//2) #output=0.0 but according operator precedence output should be 1.0 but why ,can anyone explain this.
9 Antworten
+ 3
Thanks Donna now I know how this works.
/>//>%>*>+>-
6/3=2.0
3//2=1
2.0%2=0
0*1=0
+ 1
Maninder Singh division has a higher precedence than multiplication, in pretty much any case
+ 1
BlazingMagpie confirming your comment that equal precedence operations are applied left to right
>>> 2*3%2
0
>>> 3%2*2
2
>>> 2*3//2
3
0
hinanawi That's not how operation precedence works. Multiplication and division have same precedence, so you do then in order from left to right.
0
BlazingMagpie talking programming here, sorry for not specifying
0
>>>6/3%2*3//2
>>>2%2*1
>>>2%2
>>>0