the function in python that returns extension of a file

Viewed 218

I am a beginner in Python. I would like to understand the following function, which returns the extension of that file:

def get_extn(filename):
    return filename[filename.rfind('.'):][1:]

I do not understand why there are brackets in the rfind function [] but not () and why there is : and [1:] before the bracket. I appreciate an explanation.

3 Answers
Related