Friday, April 20, 2018

DISappearing and

Python has a very rich set of operators that can be overloaded.  From __get__ to __getattr__, __repr__ to __format__, and __complex__ to __iadd__ you can modify almost every behavior of your type.  Conspicuously absent however, are the boolean operators.

This is why Django ORM and SQLAlchemy use bitwise & and | to represent SQL and / or.

Let's take a closer look at how the Python compiler treats these operators:

>>> import dis
>>> dis.dis(lambda: a & b)
  1           0 LOAD_GLOBAL              0 (a)
              3 LOAD_GLOBAL              1 (b)
              6 BINARY_AND
              7 RETURN_VALUE
>>> dis.dis(lambda: a and b)
  1           0 LOAD_GLOBAL              0 (a)
              3 JUMP_IF_FALSE_OR_POP     9
              6 LOAD_GLOBAL              1 (b)
        >>    9 RETURN_VALUE

Not only can you not override the and operator, the Python VM doesn't even have an opcode for it.

In return, Python gives you the semantics that a or b returns not True or False, but either or b (or False if neither is truthy).


30 comments:

  1. Great article and a nice way to promote online. I’m satisfied with the information that you provided
    bathroom remodeling nashville tn

    ReplyDelete
  2. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.
    air conditioning contractors palm beach county

    ReplyDelete
  3. Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading.
    tankless water heater nashville

    ReplyDelete
  4. I have read your article, it is very informative and helpful for me.I admire the valuable information you offer in your articles. Thanks for posting it..
    tree removal companies palm beach county

    ReplyDelete
  5. You have a good point here!I totally agree with what you have said!!Thanks for sharing your views...hope more people will read this article!!!
    air conditioning companies palm beach county

    ReplyDelete
  6. Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject.
    residential pest control wellington fl

    ReplyDelete
  7. Very nice bro, thanks for sharing this with us. Keep up the good work and Thank you for sharing information
    pest control companies royal palm beach fl

    ReplyDelete
  8. I think this is one of the most significant information for me. And i’m glad reading your article. But should remark on some general things, The web site style is perfect, the articles is really great : D. Good job, cheers

    Haroon Ullah

    ReplyDelete
  9. Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject. Manhattan Escorts

    ReplyDelete
  10. Superior post, maintain up with this remarkable work. It's nice to know that this subject is being additionally covered on this internet site so cheers for taking the time to review this! Thanks again as well as again! Guest Post

    ReplyDelete
  11. If your looking for Online Illinois license plate sticker renewals then you have need to come to the right place.We offer the fastest Illinois license plate sticker renewals in the state. watch series

    ReplyDelete
  12. I simply want to tell you that I am new to weblog and definitely liked this blog site. Very likely I’m going to bookmark your blog . You absolutely have wonderful stories. Cheers for sharing with us your blog. best gaming

    ReplyDelete
  13. I read this article. I think You put a great deal of exertion to make this article. I like your work. real estate closing gifts

    ReplyDelete
  14. The level of interest is high when you know how to start a super mission. I like to give my great line to perform super actions from the top zone. watch series

    ReplyDelete
  15. stunning... what an extraordinary blog, this writter who composed this article it's realy an incredible blogger, this article so moving me to be a superior individual christmas

    ReplyDelete
  16. On the off chance that you are looking for best McAfee specialized help, Our McAfee client care number and locate the best answer for it. social media agency

    ReplyDelete
  17. I can't stand by to burrow profound and the opening shot using assets that I got from you. Your richness is reviving. ecommerce website development company

    ReplyDelete
  18. Great article. On account of this blog my undertaking has really finished. online retailer

    ReplyDelete
  19. Welcome to an amazing gathering here you will get the hang of every little thing about me. gift

    ReplyDelete
  20. I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... Sarkari Naukri

    ReplyDelete
  21. Incredible article and a pleasant method to advance on the web. I'm happy with the data that you gave. judi slot

    ReplyDelete
  22. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. relationship

    ReplyDelete
  23. Positive site, where did u build up the data on this distributing? I have looked at a couple of the articles on your site presently, just as I really like your plan. An abundance of thanks a million and furthermore please keep up the solid work. high DA

    ReplyDelete
  24. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. Speedup Forex

    ReplyDelete
  25. I have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! RRB Group D Admit Card

    ReplyDelete
  26. This comment has been removed by the author.

    ReplyDelete
  27. Your different from others i've read, this was amazing I thank you for sharing this.home remedies to get rid of lice fast

    ReplyDelete
  28. Your different from others i've read, this was amazing I thank you for sharing this.We buy houses west palm beach

    ReplyDelete

  29. This was an outstanding piece of content. I really liked it. I'll be back to see more. Thanks!

    Also visit my webpage - 휴게텔
    (jk)

    ReplyDelete
  30. Hey There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely return. 메이저놀이터

    ReplyDelete