Lambda Functions
Sometimes you may need to define small one-action function. Especially it's quite useful for preprocessing data. In this case, you can use lambda
function.
Lambda function is a small anonymous function (unless you assign it to some variable) that can have many arguments, but only one expression/instruction. To define lambda function use the keyword lambda
followed by arguments. Next, set the colon sign, and define the instruction. For example, the circle_area
function can be expressed as lambda:
123456789# Import the library import math # Define lambda function area = lambda R: print("Area:", math.pi*R**2) # Calling function area(5) area(8)
Merci pour vos commentaires !
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Posez-moi des questions sur ce sujet
Résumer ce chapitre
Afficher des exemples du monde réel
Awesome!
Completion rate improved to 2.7
Lambda Functions
Glissez pour afficher le menu
Sometimes you may need to define small one-action function. Especially it's quite useful for preprocessing data. In this case, you can use lambda
function.
Lambda function is a small anonymous function (unless you assign it to some variable) that can have many arguments, but only one expression/instruction. To define lambda function use the keyword lambda
followed by arguments. Next, set the colon sign, and define the instruction. For example, the circle_area
function can be expressed as lambda:
123456789# Import the library import math # Define lambda function area = lambda R: print("Area:", math.pi*R**2) # Calling function area(5) area(8)
Merci pour vos commentaires !