How do order of operations go on Python?

前端 未结 5 1045
庸人自扰
庸人自扰 2020-12-06 06:41

My question looks like this:

  10-7//2*3+1 

I am supposed to solve the equation.

My answer seems to come out as 8 when using PEMDAS:

5条回答
  •  一向
    一向 (楼主)
    2020-12-06 07:11

    How do order of operations go on Python?

    I don't know what a PE(MD)(AS) is, but Python order of operations (order of precedence) rules go as the "Operator Precedence" table from the official documentation says they go. :)

    Keep in mind, many of these operator precedence rules are opposite in Python how they are in C or in C++, but here are the "Operator precedence" rules in Python 3:

    To read all the footnotes in the table, click on the link just above.

提交回复
热议问题