Bird
0
0

What will be the output of this code if the environment variable 'HOME' is set to '/home/user'? import os print(os.getenv('HOME'))

medium📝 Predict Output Q4 of 15
Python - Standard Library Usage
What will be the output of this code if the environment variable 'HOME' is set to '/home/user'? import os print(os.getenv('HOME'))
A/home/user
BHOME
Cnull
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.getenv behavior

    os.getenv('HOME') returns the value of 'HOME' environment variable if set, else null.
  2. Step 2: Given 'HOME' is '/home/user'

    The code prints the string '/home/user'.
  3. Final Answer:

    /home/user -> Option A
  4. Quick Check:

    os.getenv returns env var value = /home/user [OK]
Quick Trick: os.getenv returns env var value or null if missing [OK]
Common Mistakes:
  • Expecting variable name instead of value
  • Assuming it prints null when variable exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes