python program to print the contents of a directory using os module 1

python program to print the contents of a directory using os module

import os
li = os.listdir(".")
print(li)

Here is what the above code is Doing:
1. We import the os module.
2. We call the listdir() method of the os module.
3. We pass the current directory as an argument to the listdir() method.
4. We store the result in a variable called li.
5. We print the contents of the li variable.

Similar Posts