Computer >> Computer tutorials >  >> Programming >> Python

How to know/change current directory in Python shell?


You can change directory or cd in Python using the os module. It takes as input the relative/absolute path of the directory you want to switch to.

For example

>>> import os
>>> os.chdir('my_folder')

To know the current working directory or pwd use the os module.

For example

>>> import os
>>> print(os.getcwd())
/home/ayush/qna