os.getenv()
os.getenv() is a Python function in the OS Module category. Returns the value of an environment variable, or default if not set. The syntax is os.getenv(key, default=None). Parameters: key — env var name. Returns: String or default. A typical example: os.getenv("HOME") # "/home/user"
os.getenv("NONEXIST") # None
os.getenv("NONEXIST", "/tmp") # "/tmp". A close sibling is os.getcwd(), which returns the current working directory as a string. A close sibling is os.chdir(), which changes the current working directory to the given path. A close sibling is os.listdir(), which returns a list of all files and directories in the given path. A close sibling is os.mkdir(), which creates a single directory. Raises FileExistsError if it already exists. More about this category: Operating system interface — file operations, paths, environment variables. For a broader walkthrough, read the OS Module guide. Related OS Module entries: os.getcwd(), os.chdir(), os.listdir(), os.mkdir(), os.makedirs(), os.remove().