import os
print(os.path.expanduser('~'))
Here we need to import tha os then this one line can do required thing