I set an environment variable that I want to access in my Python application. How do I get its value?
To check if the key exists (returns True or False)
True
False
'HOME' in os.environ
You can also use get() when printing the key; useful if you want to use a default.
get()
print(os.environ.get('HOME', '/home/username/'))
where /home/username/ is the default
/home/username/