[PYTHON] lambda expression memo

lambda expression memo.

Anonymous function. It can be stored in a variable and used in other functions.

lamda1.py


#How to write: lamnda[argument]: [Return value]
f = lambda x: x*2
print(f(5))
#=> 10

To use in a dictionary

lamda2.py


value_map = {
    1: lambda num: num + 10,
    2: lambda num: num + 20,
    3: lambda num: num + 30
}

add_type = 2
num = 1
print(value_map[add_type](num))
#=> 21

Recommended Posts

lambda expression memo
Lambda expression
Recursive expression memo
A python lambda expression ...
python regular expression memo
lambda
gzip memo
Raspberry-pi memo
Pandas memo
Use print in a Python2 lambda expression
HackerRank memo
Python memo
python memo
graphene memo
Flask memo
pyenv memo
Matplotlib memo
pytest memo
Python memo
Install Memo
BeautifulSoup4 memo
networkx memo
python memo
tomcat memo
command memo
Generator memo.
psycopg2 memo
Python memo
SSH memo
Command memo
Memo: rtl8812
pandas memo
Shell memo
Python memo
Pycharm memo
Python memo