Python - os.pardir() method with example Last Updated : 18 May, 2020 Comments Improve Suggest changes Like Article Like Report 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.path.pardir() Note: os.pardir is '.. for UNIX based OS and '::' for Mac OS. Syntax: os.pardir Return type: a string that refers to the parent directory. Example 1: Python3 1== # Python program to demonstrate # os.pardir import os # prints .. by default print(os.pardir) Output: .. Example 2: Let's print the parent of current working directory. Python3 1== # Python program to demonstrate # os.pardir import os # current working directory path = os.getcwd() print("Current Directory:", path) # parent directory parent = os.path.join(path, os.pardir) # prints parent directory print("\nParent Directory:", os.path.abspath(parent)) Output: Current Directory: /home/geeks/Desktop/gfg Parent Directory: /home/geeks/Desktop Example 3: Getting the parent of specified path. Python3 1== # Python program to demonstrate # os.pardir import os # path path = "your/path/for/parent/directory" print("Path:", path) # parent parent = os.path.join(path, os.pardir) # prints the relative file path # for the current directory (parent) print("\nParent:", os.path.relpath(parent)) Output: Path: your/path/for/parent/directory Parent: your/path/for/parent Comment More infoAdvertise with us Next Article Python - os.pardir() method with example N nikhilaggarwal3 Follow Improve Article Tags : Python Python Programs python-os-module Python directory-program Practice Tags : python Similar Reads os.path.abspath() method - Python The os.path.abspath() method in Python's os module is used to get the full (absolute) path of a file or folder. It's useful when you're working with relative paths but need to know the exact location on your system. If you pass a relative path, it converts it to an absolute one and if the path is al 2 min read Create a File Path with Variables in Python The task is to create a file path using variables in Python. Different methods we can use are string concatenation and os.path.join(), both of which allow us to build file paths dynamically and ensure compatibility across different platforms. For example, if you have a folder named Documents and a f 3 min read How to use OS with Python List Comprehension One such module is the 'os' module, which allows interaction with the operating system. When combined with list comprehensions, the 'os' module becomes a potent tool for handling file and directory operations concisely and expressively. In this article, we will see how we can use the os module with 3 min read Python Program to Safely Create a Nested Directory Creating a nested directory in Python involves ensuring that the directory is created safely, without overwriting existing directories or causing errors. To create a nested directory we can use methods like os.makedirs(), os.path.exists(), and Path.mkdir(). In this article, we will study how to safe 2 min read Delete a directory or file using Python In this article, we will cover how to delete (remove) files and directories in Python. Python provides different methods and functions for removing files and directories. One can remove the file according to their need.Table of ContentUsing the os.remove() MethodDelete a FileRemove file with absolut 6 min read Like