What is the difference between os.environ.get("KEY") and os.environ["KEY"], and which pattern should SRE automation scripts prefer?
#Reveal answer guidance
os.environ["KEY"] raises KeyError if the variable is absent, crashing the script. os.environ.get("KEY") returns None (or a supplied default). SRE scripts should prefer os.environ.get("KEY", "default") at startup and then validate explicitly: if not value: raise SystemExit("KEY env var required"). Better still, use pydantic-settings or python-dotenv with a typed settings model — you get type coercion, validation, and a single crash-fast entry point rather than scattered KeyErrors deep in business logic.