Double Parentheses in Python
Python is one of the easiest programming languages to learn, because of it’s inherent flexibility. (This can be a good thing as well as a bad thing.)
One example of Python’s flexibility is the double parentheses. Take the following snippet for example:
print funcwrapper(3)(2)
Even an inexperienced programmer should be able to make sense of most of this. Reading from left to right, it looks like we want to print the output of a function, and we’re passing an integer - 3 - to that function. However, the second pair of parentheses doesn’t quite make sense.
This notation is different from what we would do if we wanted to pass two arguments to a function; in that case, we’d put them all inside a single pair of parentheses and separate them via commas:
print funcwrapper(3, 2)
So what does the first example using two pairs of parentheses accomplish?
The use of a double parentheses is actually an indicator of one of Python’s coolest features - and that is that functions are themselves, objects! What does this mean?
Let’s work our way up to the snippet above by first defining a very simple function - something that takes an integer Continue reading