all Python 3osfunction
os.path.isabs
os.path — making paths absolute
Check whether a path is absolute.
Syntax
os.path.isabs(path)
The rules depend on the platform. On Windows since Python 3.13 a path with one leading slash, '/foo', is not absolute: it is relative to the root of the current drive. 'C:foo' is not absolute either — it is relative to the current directory of drive C. On Unix any path starting with a slash is absolute.
Examples
import os
print(os.path.isabs('relative/path')) # → False
print(os.path.isabs(os.getcwd())) # → True (текущий каталог всегда абсолютный)
p = 'data/notes.txt'
print(os.path.isabs(p), os.path.isabs(os.path.abspath(p))) # → False True (типовая связка: проверил — и достроил через abspath)
print(os.path.isabs('')) # → False (пустая строка путём не считается)
print(os.path.isabs('/usr/bin')) # → на Unix True; на Windows False — там абсолютный путь начинается с буквы диска, 'C:\\usr\\bin'
See also
Open in the full glossarydocs.python.orgReport an inaccuracy