Home » Python

How to get current working directory in Python?

Python | getcwd() Function: Here, we are going to learn how to get the path to the current working directory in Python?
Submitted by IncludeHelp, on April 24, 2020

To get the current working directory in Python, there is a library function getcwd() in the os module.

getcwd() function does not accept any parameter and returns the path of the current working directory as string i.e. it’s return type is <class str>.

Syntax:

    # import statement
    import os

    # function call
    os. getcwd()

Python code to get current working directory

# Python code to get 
# current working directory

# importing the module
import os

# getting the current path
current_path = os.getcwd()

print("Current working directory is:", current_path)

# printing the type of getcwd() function
print("Type of \'getcwd()\' function is:", type(os.getcwd()))

Output

Current working directory is: /home/runner/FrenchBrightDaemon
Type of 'getcwd()' function is: <class 'str'>


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.