Operator precedence in Python -PEMDAS

后端 未结 2 1555
深忆病人
深忆病人 2020-12-22 12:44

I read about python following PEMDAS that is precedence of multiply is more than division.

I ran the following script

print 6*2/1*2

相关标签:
2条回答
  • 2020-12-22 13:09

    * has the same operator precedence as /. Operators in the same group evaluate left to right, so your expression evaluates as:

    6*2 = 12
    / 1 = 12
    * 2 = 24
    
    0 讨论(0)
  • 2020-12-22 13:09

    Order of precedence in Python

    P

    E

    M D Left to right

    A S Left to right

    0 讨论(0)
提交回复
热议问题