Bird
0
0

What issue arises from this code snippet if the environment variable MAX_CONNECTIONS is not set?

medium📝 Debug Q7 of 15
Python - Standard Library Usage
What issue arises from this code snippet if the environment variable MAX_CONNECTIONS is not set?
import os
max_conn = int(os.getenv('MAX_CONNECTIONS'))
print(max_conn)
ANo error, prints None
BValueError because os.getenv returns empty string
CPrints 0 by default
DTypeError because int(None) is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Behavior of os.getenv when variable missing

    os.getenv returns None if variable not set and no default provided.
  2. Step 2: Conversion to int

    int(None) raises TypeError because None cannot be converted to int.
  3. Final Answer:

    TypeError because int(None) is invalid -> Option D
  4. Quick Check:

    int(None) causes TypeError [OK]
Quick Trick: int(None) raises TypeError, provide default [OK]
Common Mistakes:
  • Assuming os.getenv returns empty string if missing
  • Expecting int conversion to default to zero
  • Not handling None before int() conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes