Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sort methods
#4
Read evaluation order and operator precedence

Quote:Python evaluates expressions from left to right. Notice that while evaluating an assignment, the right-hand side is evaluated before the left-hand side.

So in your example:
  1. it will first evaluate 3, resulting in 3
  2. then it will evaluate multi(3) - this will throw error if multi expects 2 arguments, see below
  3. then it will evaluate add(result from multi(3))
  4. then it will assign the result from item 3 to a
  5. then, on next line, it evaluate a - first term on the right-hand side.
  6. then it will evaluate a+3
  7. then it will evaluate div(result from a + 3)
  8. then it will evaluate mod(result from div(result from a + 3))
  9. then it evaluate 12
  10. then it will evaluate sub(12)
  11. then it will evaluate a + result from mod(result from div(result from a + 3)) = result from sub(12)
  12. then will assign the result to a


You did not confirm but, I would assume these are functions from operator module, although there is no multi, but mul.
So, first of all, your example is invalid, because all these functions expect 2 arguments. e.g. mul(3) will throw error

>>> from operator import mul
>>> mul(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: mul expected 2 arguments, got 1
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Sort methods - by rs74 - Jun-12-2020, 07:26 AM
RE: Sort methods - by buran - Jun-12-2020, 07:32 AM
RE: Sort methods - by rs74 - Jun-12-2020, 07:50 AM
RE: Sort methods - by buran - Jun-12-2020, 08:16 AM
RE: Sort methods - by rs74 - Jun-12-2020, 08:20 AM
RE: Sort methods - by DeaD_EyE - Jun-12-2020, 08:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,417 Apr-19-2022, 06:50 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020