Rename multiple files in Python

How can I rename the following files: abc_2000.jpg abc_2001.jpg abc_2004.jpg abc_2007.jpg into the following ones: year_2000.jpg year_2001.jpg year_2004.jpg year_2007.jpg The related code is: import os import glob files = glob.glob('abc*.jpg') for file in files: os.rename(file, '{}.txt'.format(???)) Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help … Read more