Complete the code to import the module needed to access environment variables.
import [1]
The os module is used in Python to access environment variables.
Complete the code to get the value of the environment variable named 'HOME'.
home_dir = os.[1]('HOME')
The os.getenv() function returns the value of an environment variable.
Fix the error in the code to set an environment variable 'API_KEY' to '12345'.
os.[1]['API_KEY'] = '12345'
To set an environment variable, assign it in os.environ like a dictionary.
Fill both blanks to create a dictionary of environment variables whose names start with 'APP_'.
app_vars = {key: os.environ[key] for key in os.environ if key [1] 'APP_'}The startswith method checks if a string begins with a given substring.
Fill all three blanks to safely get an environment variable 'PORT' as an integer with default 8080.
port = int(os.getenv('[1]', [2])) if os.getenv('[3]') else 8080
This code tries to get 'PORT' from environment variables. If it exists, it converts it to an integer. If not, it uses 8080 as default.