Bird
0
0

What will be the output of this Python Lambda handler?

medium📝 Predict Output Q5 of 15
AWS - Lambda
What will be the output of this Python Lambda handler?
def lambda_handler(event, context):
    return event.get('name', 'unknown')

When invoked with {} (empty dictionary) as event?
A'unknown'
BNone
CError: KeyError
D'name'
Step-by-Step Solution
Solution:
  1. Step 1: Understand the use of dict.get method

    The get method returns the value for the given key if it exists; otherwise, it returns the default value provided.
  2. Step 2: Apply get on empty event dictionary

    Since the event is empty and has no 'name' key, event.get('name', 'unknown') returns the default 'unknown'.
  3. Final Answer:

    'unknown' -> Option A
  4. Quick Check:

    dict.get returns default if key missing [OK]
Quick Trick: dict.get(key, default) returns default if key missing [OK]
Common Mistakes:
  • Expecting KeyError on missing key
  • Confusing return value with key name
  • Assuming None is returned by default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes