w3resource

Python: List home directory without absolute path

Python Basic: Exercise-132 with Solution

Write a Python program to list home directory without absolute path.

Sample Solution:-

Python Code:

import os.path
print(os.path.expanduser('~'))

Sample Output:

/home/students

Flowchart:

Flowchart: List home directory without absolute path.

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

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 Python skills with w3resource's quiz



Python: Tips of the Day

List comprehension:

>>> m = [x ** 2 for x in range(5)]
>>> m
[0, 1, 4, 9, 16]