How does os.rename function works in python?

Replit Profile: https://replit.com/@SAKSHiGoswami1

Hi @SAKSHiGoswami1 , welcome to the forums!
os.rename takes 2 arguments: the 1st is the current name of the file you want to rename, and the 2nd is the name you want the file to be.
Example:

import os
os.rename('file.py', 'sever.py')

Here, file.py is the old name, and sever.py is the new name.
After running the program, you will see the filename change.

Hope this helps!

4 Likes