What does the following sentence mean ?
In Python functions are first class data members.
What does the following sentence mean ?
In Python functions are first class data members.
See First-class Function:
Specifically, this means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.
It means that functions are represented as objects. You can easily pass them to other methods as parameters
def fun():
print "Hi"
fun()
def take(f):
f()
take(fun)
this will print "Hi" twice
Python is a hybrid language that supports both OO programming and functional programming and mostly first class functions make it functional language together with some other features such as tuples (read-only data types)
The key is that you can compose smaller functions to achieve larger goals
In many languages first class data members are things like numbers, sequences (like arrays or strings) or objects (which can be thought if as sequences of things like numbers and other sequences). These are normally passed to functions where they might mutate or effect the execution or return value. In Python (and JavaScript, and many other languages actually) functions can be passed as arguments. This gives you tremendous flexibility in composing functions and it lets you create smaller more generic functions that take functions as arguments. This can be a by mind ending at first but as you use it you will wonder why other languages create these false distinctions.