• Home
  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • Python
      • Introduction to Python
      • Python Developer
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • React
      • Introduction to React
      • React Developer
  • Interactive Training
  • Pricing
  • Brainstorm

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds

Courses

  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React
    • Introduction to React
    • React Developer

Newsletter

Subscribe to our free monthly newsletter, for a quick update on Python, JavaScript, and React news

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

Python Developer -

Lesson 13 of 34

Lesson Progress: 0%

Lesson Progress: 0%
Lesson Incomplete
← Previous: Multiple Function Arguments
Lesson 13 of 34
Next: Closures →
Code Example
# lambda function
add = lambda a, b: a + b
print(add(2, 3))

# the lambda function does the same as
def add(a, b):
    return a + b
print(add(2, 3))

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • A lambda is a short way to make a small function in one line.
  • It can take inputs like a and b and quickly give back a result.
  • The lambda example and the def example do the same job.
  • Use print() to see the answer that the function returns.
Code Example
double = lambda x: x * 2
print(double(4))

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • A lambda is a mini-tool that lets you write a whole math rule on just one short line.
  • You give it a name and tell it what to do, then you can use that name whenever you want to run your rule.
Code Example
# A quick way to say hello to someone
greet = lambda name: "Hello " + name

print(greet("Sam"))

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • You can use a lambda to build a quick "greeting machine" that adds words together for you.
  • Just give the machine a name like greet, and it will put "Hello" in front of any name you type.
Code Example
shout = lambda word: word.upper()

print(shout("hello"))

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • You can make a mini-tool that changes how words look, like turning small letters into big LOUD letters.
  • By using .upper() inside your lambda, you tell Python to "shout" whatever word you give it.
Code Example
is_even = lambda num: num % 2 == 0

print(is_even(4))
print(is_even(5))

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • You can build a quick "number checker" that knows if a number is even or odd.
  • The % 2 == 0 part is a math trick that asks Python if a number can be split perfectly into two groups.
  • If the number is even, the machine gives you a True answer; if it's odd, it gives you a False answer.
Code Example
even_or_odd = lambda n: "Even" if n % 2 == 0 else "Odd"

print(even_or_odd(4))
print(even_or_odd(7))

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • This lambda quickly checks a number and decides if it is even or odd.
  • If the number can be divided by 2, it returns “Even”, otherwise it returns “Odd”.
  • The print() lines show the result for each number you test.
Code Example
# Rule: If the score is 50 or more, you Pass. Otherwise, you Fail.
grade = lambda score: "Pass" if score >= 50 else "Fail"

print(grade(75))
print(grade(30))

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • This mini-tool works like a smart judge that looks at a score and makes a choice between two answers.
  • It uses the words if and else to decide which message to send back to you.
  • If the number is high enough, it says "Pass," but if it's too low, it automatically switches to say "Fail."
Code Example
# Rule: If the hour is before 18 (6 PM), it is Day. Otherwise, it is Night.
time_of_day = lambda hour: "Day" if hour < 18 else "Night"

print(time_of_day(10))
print(time_of_day(20))

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • This lambda function checks the hour and chooses between “Day” or “Night”.
  • If the hour is less than 18, it returns “Day”; otherwise it returns “Night”.
  • The print() lines show what the function returns for different times.

Test Incomplete

What is a lambda function in Python?

Question #

1/15

Score

0/0 - 0.0 %