Lambda Functions

So far, we've always defined functions using def, but Python provides a second way of creating functions:

The lambda keyword is used to create simple anonymous functions. Lambda functions cannot contain control structures (no branches or loops), nor do they have a return statement: The value returned is simply whatever the expression

★The QString.simplified() method is like our simplify!) function called with just one argument.

evaluates to. Lambda functions can be closures, a topic covered later. In this Clo-example, we have assigned the lambda function to the variable cube, which we sures can now use, for example: cube(3) which will return 27. » 64

Some Python programmers dislike lambda; certainly it is not needed since def can be used to create any function we want. However, when we start on GUI programming we will see one context where lambda can be useful, although we will also show alternatives that don't use it.

Was this article helpful?

0 0


The main focus of this report is to show how to get involved in video marketing on the run, how to rank quickly on YouTube and Google using FREE semi-automatic tools and services. QUICKLY AND FREE. I will show methods and techniques I use to rank my videos, as well as free resources and tools to make video clips, to get backlinks and free traffic.

Get My Free Ebook

Post a comment