Suppose I have a file test.pdf but I changed the extension to jpeg such that the file is now test.jpeg. The actual file format should still be a pdf file as the file signature for a pdf is 25 50 44 46 2d and the file signature for a jpeg is either FF D8 FF DB or FF D8 FF EE and a couple other ones. 
I tried it with a few suggestions from How can I check the extension of a file?. But they all appear to just be finding what the apparent file extension is. For example,
>>> file_name, file_extension = os.path.splitext("/Users/mark/Desktop/test.jpeg")
>>> file_extension
'.jpeg'
>>> 
As shown the file extension provided in the end is .jpeg but the real file extension is actually still .pdf.