.basename()

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...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy