Python os.getenv() Method
Example
Print the value of the environment variable key "HOME":
#Import os Library
import os
#print value of the environment variable key
print (os.getenv("HOME"))
Try it Yourself »
Definition and Usage
The os.getenv()
method returns the value of the environment variable key, if it exists.
Note: This method is available for both Unix and Windows.
Syntax
os.getenv(key, default)
Parameter Values
Parameter | Description |
---|---|
key | Required. The name of the environment variable key |
default | Optional. Default value in case the key does not exist. If omitted, the value is 'None' |
Technical Details
Return Value: | A str value, representing value of the environment variable key.
If key does not exists, it returns the value of the default parameter |
---|---|
Python Version: | 1.6 |