Abishek Viswanath Abishek Viswanath - 1 year ago 97
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('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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download