Bird
0
0

Given this Flask snippet:

medium📝 Predict Output Q4 of 15
Flask - Deployment
Given this Flask snippet:
import os
app_secret = os.getenv('APP_SECRET', 'defaultsecret')
print(app_secret)

If the environment variable APP_SECRET is not set, what will be printed?
ANone
Bdefaultsecret
CAPP_SECRET
D'' (empty string)
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.getenv behavior with default

    os.getenv returns the environment variable value if set; otherwise returns the default provided.
  2. Step 2: Apply to given code

    Since APP_SECRET is not set, os.getenv returns 'defaultsecret', which is printed.
  3. Final Answer:

    defaultsecret -> Option B
  4. Quick Check:

    Unset env var returns default value [OK]
Quick Trick: Unset env vars return default if provided in getenv [OK]
Common Mistakes:
MISTAKES
  • Assuming None is printed when var is missing
  • Thinking variable name string is printed
  • Expecting empty string instead of default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes