The isabs()
function is defined in the path
sub-module of the os
module. It is used to determine whether a given pathname represents an absolute path or not.
An absolute path is one that begins from the root directory of a file system, regardless of the current working directory. In a Unix-like system, an absolute path starts with a forward slash ('/'), while a relative path doesn't.
To use the function, we first need to import it in our program as follows.
from os.path import isabs
copy
isabs(path)
copy
The function returns a boolean value, True
if the path is an absolute path and False
otherwise. It does not validate whether the path actually exists.
In the above example, we have a list of paths, we used a for loop to iterate over the paths calling the isabs()
function during each iteration. Only the absolute paths are printed.