Bird
0
0

Given this Python code snippet running in a Google Cloud Function:

medium📝 Predict Output Q13 of 15
GCP - Cloud Functions
Given this Python code snippet running in a Google Cloud Function:
import os
api_key = os.getenv('API_KEY')
print(f"Key: {api_key}")

If the environment variable API_KEY is not set, what will be printed?
AKey: API_KEY
BKey:
CKey: None
DError: Environment variable not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.getenv behavior

    When the environment variable is missing, os.getenv returns None by default.
  2. Step 2: Analyze the print output

    The f-string converts None to the string 'None', so the output is 'Key: None'.
  3. Final Answer:

    Key: None -> Option C
  4. Quick Check:

    Missing env var returns None [OK]
Quick Trick: os.getenv returns None if variable missing [OK]
Common Mistakes:
  • Assuming empty string is returned
  • Expecting an error to be raised
  • Thinking variable name is printed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes