I have came across this logic:
return 2 * f(arg)
return arg + 1
f_2 = f2(f1)
The passing of functions to other functions is a common idiom in so-called functional programming languages like LISP, Scheme, Haskell, etc. Python is sometimes referred to as a "multi-paradigm language" because it has some features of functional languages (as well as of imperative/structured and object-oriented languages).
So while it is considered an advanced technique, it is hardly uncommon to see it in Python. Python even has a language keyword (
lambda) to let you define short functions "in line" when calling a function, so you don't have to give them a name and define them elsewhere. It also has built-in functions like
reduce, which are explicitly designed to work with functions passed in to them; these are borrowed from the aforementioned functional languages. And a commonly-used language feature, decorators, is basically a function that takes a function and returns a function.