Bird
Raised Fist0

What will this code print if the environment variable 'DEBUG' is not set? import os print(os.environ.get('DEBUG', 'false'))

medium📝 Predict Output Q5 of Q15
Python - Standard Library Usage
What will this code print if the environment variable 'DEBUG' is not set? import os print(os.environ.get('DEBUG', 'false'))
Anull
Btrue
CError
Dfalse
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.environ.get with default

    os.environ.get('DEBUG', 'false') returns the value of 'DEBUG' if set, else returns the default 'false'.
  2. Step 2: Given 'DEBUG' is not set

    The code prints the default string 'false'.
  3. Final Answer:

    false -> Option D
  4. Quick Check:

    os.environ.get with default returns default if missing [OK]
Quick Trick: Use get(key, default) to avoid errors if env var missing [OK]
Common Mistakes:
MISTAKES
  • Expecting null instead of default value
  • Assuming error occurs if variable missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes