Python·100 questionsHow to read environment variables in Python?SaveUpdated: 2026-08-31Answer•import os.•os.environ['KEY'] (will crash if missing).•os.getenv('KEY', default) is safer.•Convert types explicitly (int/bool).•For .env, use python-dotenv (in dev).Ask AI to clarifyWas this answer helpful?HelpfulNot helpfulSuggest an improvement