os.rename():-
We can move our file in Python using the os.rename() method. But you need to be aware that your source and destination file should be in the same disk.
import os
os.rename("path/to/current/file.foo", "path/to/new/destination/for/file.foo")
shutil.move():-
We can also use shutil.move() method to move our file in Python. If your source and destination file are at the different disk in that case also this method works. If the destination file is on the current file system where the resource file is also present then shutil.move() uses os.rename()to move the file. Otherwise, shutil.move() copies the source file to the destination file using shutil.copy2() and then removes the source.
import shutil
shutil.move("path/to/current/file.foo", "path/to/new/destination/for/file.foo")
import pathlib
Path("path/to/current/file.foo").rename("path/to/new/destination/for/file.foo")
If you are looking for upskilling yourself in python you can join our Python Certification and learn from an industry expert.