os.getcwd() vs os.chdir()
os.getcwd() and os.chdir() are both Python OS Module APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. os.getcwd(): Returns the current working directory as a string. Its syntax is os.getcwd(), and it returns string path os.chdir(): Changes the current working directory to the given path. Its syntax is os.chdir(path), and it returns none Example of os.getcwd(): import os
os.getcwd() # "/home/user/project". Example of os.chdir(): os.chdir("/tmp")
os.getcwd() # "/tmp". Read the full references for os.getcwd() and os.chdir() to see parameters, edge cases, and example code side by side. Other OS Module APIs worth comparing: os.listdir(), os.mkdir(), os.makedirs(), os.remove(), os.rmdir(), os.removedirs(). Both belong to the OS Module category in the Python Reference documentation. Try both in the Python playground to see the behavioral difference live.