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 Jacker

Tube Jacker

Download Tube Jacker And Discover Everything You Need To Know About Jacking Unlimited Traffic From The Video Giant. The drop dead easy way to create winning video campaigns that will FLOOD your website with unstoppable FREE traffic, all on complete and total autopilot. How to exploit a sneaky method of boosting exposure and getting your videos to the top of Google within 72 hours, guaranteed.

Get My Free Ebook


Post a comment