Python: List home directory without absolute path
Python Basic: Exercise-132 with Solution
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/python-basic-exercise-132.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics