In Python, OS module provides various functions to interact with the operating system. This module comes under the Python standard utility module, so there is no need to install it manually.
os.pardir is a constant string used by the operating system to refer to the parent directory. This method is also available via
os.pardir is ‘
.. for UNIX based OS and ‘
::‘ for Mac OS.
Return type: a string that refers to the parent directory.
Example 2: Let’s print the parent of current working directory.
Current Directory: /home/geeks/Desktop/gfg Parent Directory: /home/geeks/Desktop
Example 3: Getting the parent of specified path.
Path: your/path/for/parent/directory Parent: your/path/for/parent
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course