Python Forum
how operators are implemented as function calls
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how operators are implemented as function calls
#2
Skaperen Wrote:i've noted that a few posts show that some of you know about expressing an assembly-like language that expresses what goes on inside Python (or at least inside CPython).
Do you mean bytecode? Try the dis module
>>> import dis
>>> dis.dis("mydict[x] = y")
  1           0 LOAD_NAME                0 (y)
              3 LOAD_NAME                1 (mydict)
              6 LOAD_NAME                2 (x)
              9 STORE_SUBSCR
             10 LOAD_CONST               0 (None)
             13 RETURN_VALUE
>>> dis.dis("y = mydict[x]")
  1           0 LOAD_NAME                0 (mydict)
              3 LOAD_NAME                1 (x)
              6 BINARY_SUBSCR
              7 STORE_NAME               2 (y)
             10 LOAD_CONST               0 (None)
             13 RETURN_VALUE
Reply


Messages In This Thread
RE: how operators are implemented as function calls - by Gribouillis - Dec-14-2018, 06:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  optimizing calls to isinstance() Skaperen 0 940 Nov-27-2022, 01:33 AM
Last Post: Skaperen
  omitting arguments in function/method calls Skaperen 10 4,136 Nov-24-2019, 10:13 PM
Last Post: Gribouillis
  overload operators anjita 4 2,615 Jan-04-2019, 12:31 PM
Last Post: buran
  has anyone implemented a sort command in Python? Skaperen 10 5,422 Dec-20-2018, 05:44 AM
Last Post: Skaperen
  Ugh, Someone Went and Implemented Case ichabod801 2 2,799 Sep-15-2017, 09:46 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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