Print environment variables in Python

In this article, we will see a how to print environment variables in Python.

We cab use environ attribute of os module for accessing environment variables using python program. This attribute gives environment dictionary which contains environment variables and its corresponding values.

Now, Let’s see given below Python code:

Output:

Now, let’s print only environment variables, so for this, we need only keys of environment dictionary.
Below is the Python code given:

Output:

That’s all about how to print environment variables in Python

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *