×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

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'>
Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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