Lambda Expression คือ การประกาศฟังก์ชันเล็ก ๆ ที่สร้างขึ้นมาเฉพาะกิจ ในภาษา Python เป็น Anonymous Function คือ ฟังก์ชันนิรนาม ที่ประกาศโดยไม่ได้ตั้งชื่อ การไม่ได้ประกาศฟังก์ชันอย่างเต็มรูปแบบ ความกระชับของโค้ด และการไม่ได้ตั้งชื่อ ทำให้มีข้อดี เหมาะกับใช้ซ้อนในฟังก์ชั่นอื่น

เราสามารถสร้าง Lambda Expression ให้รับ Parameter กี่ตัวก็ได้ แต่ Lambda Function นั้นต้องประกอบด้วย 1 Expression เท่านั้น โดยไม่ต้องระบุ return เพราะ ​Lambda Function จะ return Expression นั้นโดยอัตโนมัติ

เรามาเริ่มกันเลยดีกว่า

Open In Colab

แชร์ให้เพื่อน:

Surapong Kanoktipsatharporn on FacebookSurapong Kanoktipsatharporn on LinkedinSurapong Kanoktipsatharporn on Rss
Surapong Kanoktipsatharporn
Solutions Architect at Bua Labs
The ultimate test of your knowledge is your capacity to convey it to another.

Published by Surapong Kanoktipsatharporn

The ultimate test of your knowledge is your capacity to convey it to another.