Advanced Topic: Functional Programming

You don't need to know functional programming to develop Python code, but learning it can reduce the amount of code you write.

apply(), filter(), map(), reduce

The apply(function, args, [keywords]) function needs a callable object as the function argument, which it calls with args as the argument list (and keywords as the named argument list). args is a sequence, keywords a dictionary.

The function

>>> def hello(str):
...   print "hello " + str
...

can be called with apply() like this:

>>> apply(hello,("Bobby",))
hello Bobby

Without apply() it's called like this.

>>> hello("Bobby")
hello Bobby

You can use apply()to call several functions. Or you can have several functions operating on the same data. ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.