- To check if a file exists .
The above code checks if there is a file called p.py in the current directory and prints True or False. Initially the code checks for a file called k.py which is not present .So it prints False. Then in the 2 nd code, it checks for a file called p.py which is present. So it prints True.
- Rename a file.
Here p.py is the old name .’renamed.py’ is the new name.
- Delete a file.
The above code removes or deletes renamed.py file.