os.path.join() method in Python

The os.path.join() Method in Python joins one or more path components intelligently. This method concatenates various path components with exactly one directory separator (‘/’) following each non-empty part except the last path component. If the last path component to be joined is empty then a directory separator (‘/’) is put at the end. 

If a path component represents an absolute path, then all previous components joined are discarded, and joining continues from the absolute path component.

Python | os.path.join() method

Os Path Module is a sub-module of the OS module in Python used for common pathname manipulation. In this article, we will learn about os.path.join() and handling file paths safely in Python OS.

Similar Reads

Python os.path.join() Method Syntax

Syntax: os.path.join(path, *paths)  Parameter:  path: A path-like object representing a file system path.  *path: A path-like object representing a file system path. It represents the path components to be joined. A path-like object is either a string or bytes object representing a path. Note: The special syntax *args (here *paths) in function definitions in python is used to pass a variable number of arguments to a function.  Return Type: This method returns a string which represents the concatenated path components....

os.path.join() method in Python

The os.path.join() Method in Python joins one or more path components intelligently. This method concatenates various path components with exactly one directory separator (‘/’) following each non-empty part except the last path component. If the last path component to be joined is empty then a directory separator (‘/’) is put at the end....

os.path.join() Function Examples and Uses Cases

Below are some examples and uses cases by which we can join file paths and handling file paths safely in Python OS....