Home  >  Article  >  Backend Development  >  Introduction to the basic use of lambda expressions in python

Introduction to the basic use of lambda expressions in python

高洛峰
高洛峰Original
2017-03-22 11:47:211298browse

This article explains in detail the basic usage of lambda expressions in python

lambdaExpression, also called anonymous function, is an ordinary function' The format of the mini version of '

lambda expression:

lambda formal parameter: expression

func1 = lambda x:x+1

func1(10 )

>>>11

As can be seen from the above example, the lambda function does not need to manually define the return value. The result of the expression will be returned directly as the return value.

For example, define a lambda function and add a bitch string in front of each string.

func2 = lambda name:"bitch "+ name

print func2("jolin")

>>>bitch jolin

The above is the detailed content of Introduction to the basic use of lambda expressions in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn