Bird
0
0

Consider this AWS Lambda Python function:

medium📝 Predict Output Q4 of 15
AWS - Lambda
Consider this AWS Lambda Python function:
def lambda_handler(event, context):
    user = event.get('user', 'Anonymous')
    return f"Welcome, {user}!"

What will be the output if the event is {}?
A"Welcome, Anonymous!"
B"Welcome, Guest!"
CKeyError exception
D"Welcome, None!"
Step-by-Step Solution
Solution:
  1. Step 1: Understand event.get()

    event.get('user', 'Anonymous') returns 'Anonymous' if 'user' key is missing.
  2. Step 2: Event is empty dict

    Since event = {}, 'user' key is missing, so default 'Anonymous' is used.
  3. Final Answer:

    "Welcome, Anonymous!" -> Option A
  4. Quick Check:

    event.get returns default if key missing [OK]
Quick Trick: event.get returns default if key missing [OK]
Common Mistakes:
MISTAKES
  • Assuming KeyError on missing key
  • Confusing default value in get()
  • Assuming 'Guest' instead of 'Anonymous'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes