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
Tube Traffic Ninja

Tube Traffic Ninja

Discover How You Can Quickly And Easily Dominate Google and YouTube... With Simple Cash Generating Videos. Did you know that YouTube is the second largest search website on the entire Internet? YouTube gets more daily searches than Bing and Yahoo. In fact, there is only one search engine that gets more action.

Get My Free Ebook

Post a comment