What you see here is a function that has two times slicing syntax. For objects that support slicing syntax, one can write:
object[f:t]
with f
and t
indices. You then get a subsequence that starts by f
and ends with t
(t
is exclusive). If f
or t
are not provided, that usually means that we slice from the beginning, or to the end.
The function in your question is a bit cryptical, and actually is equivalent to:
def get_extn(filename):
f = filename.rfind('.')
filename = filename[f:]
return filename[1:]
So first we obtain the index of the last dot, then we construct a substring that starts from f
, and finally we construct a substring from that substring that starts at index 1 (thus removing the first character which is a '.'
).