A path is a string that specifies the location of a file or folder in a file system . There are two types of paths: relative and absolute.

Relative path

 A relative path is a path that is relative to the current working directory of the program or the user. It describes the location of a file or folder without starting from the root of the file system.  

For example, if the current working directory is “D:\python programs”, then the relative path of “Book.txt” in the same folder is just “Book.txt”. Similarly, the relative path of “Chapter1.txt” in a subfolder named “Chapters” is “Chapters\Chapter1.txt”.

A relative path can use “…” to refer to the parent folder of the current working directory. For example, if the current working directory is “D:\python programs\Chapters”, then the relative path of “Book.txt” in the parent folder is "…\Book.txt".

Absolute path

An absolute path is a path that starts from the root of the file system . It describes the location of a file or folder regardless of the current working directory of the program or the user.

For example, the absolute path of “Book.txt” in “D:\python programs” is “D:\python programs\Book.txt”. Similarly, the absolute path of “Chapter1.txt” in a subfolder named “Chapters” is “D:\python programs\Chapters\Chapter1.txt”. 

An absolute path always starts with a drive letter (such as “C:”, “D:”, etc.) followed by a colon and a backslash.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.