2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python lambda解説

Last updated at Posted at 2022-09-24

lambdaとは?

無名関数のこと。
関数を短く書けて便利。
関数名がないので、何回も使いまわしたい関数には使わない。

書き方

基本

lambda 引数 : 処理

lambdaを使わない例と、使った例

lambdaなし

def example(x, y):
    return x + y

lambdaで書いた場合

lambda x,y : x+y

関数名なしで、短く書ける

lambdaの引数に値を入れる時

さっきの例のxとyに値を入れる時の書き方

(lambda 引数:処理)(引数に入れたい値) と書くので、
(lambda x,y : x+y)(1,2)
となる
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?