.dirname()

Published Jun 25, 2022
Contribute to Docs

The .dirname() method returns the part of the pathname ranging from the start to the last forward-slash.

Syntax

os.path.dirname(path_string)

The path_string must be a string or byte data type.

Codebyte Example

The following example showcases the .dirname() method using a Codecademy URL:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy