Chained Comparison Operators in Python
Arpit Bhayani (~arpit71) |
We explore the internals of Python and answer
- how Chained Comparison Operators are evaluated
- how Python implements short-circuit evaluations
On top of that, we alter the evaluation strategy and make it more C-like.
Here's the outline:
- Chained Comparison Operators
- How Python and C differ in evaluation
- Disassembling and walkthrough
- Short-circuit evaluation
- Tracing the CPython code
- How python evaluates
- Altering to make it a C-like
- Disassembling and walkthrough again
Basic working knowledge of Python would be good to have.
Here's me explaining this: https://www.youtube.com/watch?v=zz2Lu5ht_jA
A detailed writeup about this: https://arpitbhayani.me/blogs/chained-operators-python
I tweak CPython for fun and try to understand how it works. I am working as Sr. Engineering Manager - SRE at Unacademy. Prior to this worked at Amazon and Practo. I run a CS Engineering focussed newsletter https://arpitbhayani.me/newsletter where I write and share an essay about programming languages internals, deep dives on some super-clever algorithms, and few tips on building scalable distributed systems. The newsletter currently has close to 1200+ subscribers.
Essays and Blogs: https://arpitbhayani.me/blogs
YouTube Channel: https://www.youtube.com/channel/UC_b1GUJv_2QiMP4BxC9-Dxg
LinkedIn Profile: https://www.linkedin.com/in/arpitbhayani/