OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub-module of OS module in Python used for common pathname manipulation.
os.path.join() method in Python join 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 seperator (‘/’) 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.
Syntax: os.path.join(path, *paths)
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.
/home/User/Desktop/file.txt /home/file.txt /home /home/User/Public/Documents/
- Difference between Method Overloading and Method Overriding in Python
- class method vs static method in Python
- Python | os.dup() method
- Python | set() method
- Python | next() method
- Python | os.sched_rr_get_interval() method
- Python | Tensorflow exp() method
- Python | sympy.tan() method
- Python | sympy.sin() method
- Python | os.sched_setaffinity() method
- Python | os.getlogin() method
- Python | os.sched_get_priority_min() method
- Python PIL | ImageOps.fit() method
- Python | os.getpid() method
- Python | sympy.lcm() method
- Python - os.pardir() method with example
- Python | os.sched_get_priority_max() method
- Python | sympy.cos() method
- Python | os.uname() method
- Python | os.times() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.