What do you mean 'recognize'? The file name is a string, you just need to match the end of that string.
You can use os.path.splitext(filename.ext) to get ('filename', '.ext'), or just test 'filename.ext'.endswith('.ext'), or 'filename.ext'[-4:] == '.ext'. Throw a 'FiLeNaMe.eXt'.lower() in there to catch weird case situations.
Right. I wasn't even aware of the existence of the OS module until now and I was under the impression Python didn't read file extensions just like that lol. It seems I have a crapton of stuff to learn.