Yasoob Khalid 7/31/2019

Python mind-teaser: Make the function return True

Read Original

This article presents a Python programming puzzle: make a specific function return True. It details two solutions. The first uses a custom class that overrides the __add__ method to manipulate how addition works. The second, simpler solution leverages Python's integer interning (caching of integers from -5 to 256) by using the value -7 to pass the function's identity checks with the 'is' operator.

Python mind-teaser: Make the function return True

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week