Skip to content
← Python for AI/ML · all 50 levels

lambda

Level 38 of 50 · Functions

Level 38 of 50

lambda

one-line functions with mangoes. Watch the reel, then work through it below: run the code, take the quiz, keep the cheat sheet.

📒 Open the cheat sheet
SanaMangoes, 300 a kilo! Do I really need a whole def for this?
TeacherNope! A tiny function, in one line. lambda!
aam.py
price = lambda kg: kg * 300
print(price(2))
Teacherlambda, the input, a colon, then the answer. 2 kilos? 600!
SanaWait, where is the return?
TeacherNo return needed! lambda returns whatever comes after the colon!
aam.py
def price(kg):
    return kg * 300

price = lambda kg: kg * 300
TeacherSame function: def style vs lambda style. lambda is the short one!

⏸ Pause & predict: what prints?

double = lambda x: x * 2
print(double("ha"))
Next: map & filter →← Scope

Where this leads

Python is step one. Building AI that ships is the rest.

The diploma takes you from zero to deployed computer vision, LLM and agent projects, with engineers who build them for a living. Already code? The bootcamp does it in three months.