Python: List home directory without absolute path
List Home Directory
Write a Python program to list the home directory without an absolute path.
Sample Solution:
Python Code:
# Import the 'os.path' module to work with file paths and directories.
import os.path
# Use the 'os.path.expanduser()' function to expand the '~' character to the user's home directory.
# It returns the absolute path to the user's home directory.
print(os.path.expanduser('~'))
Sample Output:
/home/students
Flowchart:
Python Code Editor:
Previous: Write a Python program to split a variable length string into variables.
Next: Write a Python program to calculate the time runs (difference between start and current time)of a program.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics