Abishek Viswanath Abishek Viswanath - 18 days ago 6
Python Question

Calling functions using variables in python 2

I am a beginner in programming. I chose to start with python. While exploring it, I found out that you can call Functions with variables.

For example:

def bar(arg):
return arg

f=bar
f('foo') #returns 'foo'


What do you call it when a function is called like the one in above? Is there any special name for it?

Answer

There is no special name for it, but there are two related concepts that you should look into

  • first class objects
  • callables in python

A function is a first class object. Just like a variable, it can be assigned, passed as argument, returned as value. Contrary to a variable, it can be called by using parentheses