How to change directory in python?

OS module – The function in the os module does the operating system related task such as creating a directory, fetching contents, deleting the current directory, etc.
So to change the current working directory we use os module in python.
With os module we use chdir() function to change the directory.
syntax:-
import os os.chdir("path of the new directory")
We have changed the directory but for confirming it we can use getcwd() function.
syntax:-
import os os.chdir("path of new directory") a=os.getcwd() print(a)
In this way we can change the directory in python just by using chdir() function.
Subscribe
Login
Please login to comment
0 Discussion