# Environment variables in Python

To get an variable, retrieve if from os.environ

    print(os.environ['HOME'])


It’s just like a dictionary, so you can print all of the entries:

    print(os.environ)


Just like a dictionary, the get() method will return None if the requested key isn’t present, so it never raises an KeyError, and can take a default value:

    print(os.environ.get('SPAM', 'EGGS'))


The os.getenv() function behaves exactly the same way:

    print(os.getenv('SPAM', 'EGGS'))
`