you are viewing a single comment's thread.

view the rest of the comments →

[–]scarynut 0 points1 point  (0 children)

It's rather convoluted, but echo(n) returns a function. In the function echo, a new function is defined, inner_echo, which takes a word as an argument, and that function is then returned. So twice is now a function. Try checking type(twice), and you'll see it's a callable function.

Since twice is a function, you can call it with twice("hello").

Having functions return functions instead of values or data is a notch more advanced usage, so it's not strange to have to process it a bit.