Python os.getcwd() method
The os.getcwd()
method returns the current working directory of a process as a string. The getcwd()
is a built-in function of the operating system module and comes default with Python.
Syntax
The syntax of os.getcwd()
method is:
os.getcwd()
Parameters
The os.getcwd()
method does not take any parameters.
Return Value
The os.getcwd()
method returns a string representing the location of the current working directory of a process.
Example - Get the current working directory in Python
The getcwd stands for “get current working directory,” and we can use the os.getcwd()
function to get the location of the current working directory.
# import os module
import os
# get the current working directory path
current_directory = os.getcwd()
# print the directory path
print("Current working Directory Path", current_directory)
Output
Current working Directory Path c:\Python\Code
Conclusion
The os.getcwd()
method is a built-in function of the operating system module, mainly used to get the current working directory of a process in a string format.