The Python listdir() function available under os package is used to listing all content of a directory. So you can simply print the results of the listdir() function. This will show files as well as directories. This function accepts an argument as a directory location.
Here our requirement is to list only files (not directories). So program needs to loop through the array resulted by listdir() and print only files ignoring rest.
Save the above script in a file (eg: myScript.py), Then execute this Python script on command line. You will see the results like below: Output: