Bird
0
0

Given this Python code snippet in a microservice:

medium📝 Analysis Q4 of 15
Microservices - Configuration and Secrets Management
Given this Python code snippet in a microservice:
import os

mode = os.getenv('MODE', 'production')
print(f"Running in {mode} mode")

What will be printed if the environment variable MODE is not set?
AError: MODE variable not found
BRunning in production mode
CRunning in mode mode
DRunning in None mode
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.getenv default behavior

    os.getenv returns the environment variable value or the default if not set.
  2. Step 2: Apply to code

    Since MODE is not set, it returns 'production' as default, printing 'Running in production mode'.
  3. Final Answer:

    Running in production mode -> Option B
  4. Quick Check:

    os.getenv default used = D [OK]
Quick Trick: os.getenv returns default if env var missing [OK]
Common Mistakes:
  • Assuming None is returned if variable missing
  • Expecting an error when variable is unset
  • Confusing variable name with value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes