Python Goes Meta: Functions Returning Functions, Oh My!

This is the inaugural post in an occasional series introducing more-than-basic functionality in Python. It’s commonly recognized that Python is an easy language to start learning, but not an easy language to fully master due to its size and scope. My intent here isn’t to give a systematic intro to post-basic Python but to share bits and pieces of the language that I’ve stumbled upon and found quirky or neat. Today we’ll look at how functions are objects in Python, and how to create function factories (functions that create more functions). Keep exploring! Can you return a function from a function in Python? That’s a leading question; of course the answer is yes. But why the heck would you ever want to return a function from a function? And how might you use this functionality? Let’s take a step back. Did you know you can define a function inside a function? It looks something like this. That’s admittedly a silly

read more Python Goes Meta: Functions Returning Functions, Oh My!