Python | os.getenvb() method Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. os.getenvb() method in Python is bytes version of os.getenv() method. This method also returns the value of the environment variable associated with specified key. But unlike os.getenv() method, it accepts a bytes object as the key and returns a bytes object as the value of the environment variable associated with specified key. The functionality of os.getenvb() method is available only if the native OS type of the environment is bytes. For example, Windows do not have bytes as the native OS type of the environment so the functionality of os.getenvb() method is not available on Windows. Syntax: os.getenvb(key, default = None) Parameters: key: A bytes object denoting the name of environment variable default (optional) : A string denoting the default value in case key does not exists. If omitted default is set to 'None'. Return Type: This method returns a bytes object which denotes the value of the environment variable associated with specified key. In case key does not exists it returns the value of default parameter. Code #1: use of os.getenvb() method Python3 # Python program to explain os.getenvb() method # importing os module import os # Get the value of 'HOME' # environment variable key = b'HOME' value = os.getenvb(key) # Print the value of 'HOME' # environment variable print("Value of 'HOME' environment variable :", value) # Get the value of 'JAVA_HOME' # environment variable key = b'JAVA_HOME' value = os.getenvb(key) # Print the value of 'JAVA_HOME' # environment variable print("Value of 'JAVA_HOME' environment variable :", value) Output: Value of 'HOME' environment variable : b'/home/ihritik' Value of 'JAVA_HOME' environment variable : b'/opt/jdk-10.0.1' Code #2: If key does not exist Python3 # Python program to explain os.getenvb() method # importing os module import os # Get the value of 'home' # environment variable key = b'home' value = os.getenvb(key) # Print the value of 'home' # environment variable print("Value of 'home' environment variable :", value) Output: Value of 'home' environment variable : None Code #3: Explicitly specifying default parameter Python3 # Python program to explain os.getenvb() method # importing os module import os # Get the value of 'home' # environment variable key = b'home' value = os.getenvb(key, default = "value does not exist") # Print the value of 'home' # environment variable print("Value of 'home' environment variable :", value) Output: Value of 'home' environment variable : value does not exist Reference: https://docs.python.org/3/library/os.html#os.getenvb() Comment More infoAdvertise with us Next Article Python | os.getcwd() method I ihritik Follow Improve Article Tags : Python python-os-module Practice Tags : python Similar Reads Python | os.getenv() method OS module in Python provides functions for interacting with the operating system. OS comes under Python OS env standard utility modules. This module provides a portable way of using operating system-dependent functionality. os.getenv() method in Python OS env returns the value of the os environment 4 min read Python | os.getcwdb() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. All functions in os module raise OSError in the case of invalid or inaccessible f 1 min read Python | os.getlogin() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.getlogin() method in Python is used to get the name of the user logged in on t 1 min read Python | os.getcwd() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. All functions in os module raise OSError in the case of invalid or inaccessible f 2 min read Python | os.getsid() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. All functions in os module raise OSError in the case of invalid or inaccessible f 2 min read Python | os.getrandom() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. os.getrandom() method is used to generate a string of size random bytes suitable 2 min read Like