How can I find all files in a directory with a specific extension using Python?

I am trying to open a directory in Python and I want to find all files with a particular extension which are in that directory, the extension can be txt, jpg, jpeg, png, etc. For example, this will help me filter all the files in my directory containing the txt extension if I want to perform file processing in Python, this can also help me work on all images (jpg, jpeg, png) if I know how to filter all images from my directory instead of opening them one by one. Please provide me with efficient methods of doing this, and do provide example code for these methods.