.basename()

Published Jun 25, 2022
Contribute to Docs

The .basename() method returns the part of a pathname after the last forward-slash.

Syntax

os.path.basename(path_string)

The path_string must be a string or byte data type.

Codebyte Example

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

Code
Output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy