def get_ext(fname):
dot = fname.rfind(’.’)
if dot == -1:
return’’
else:
return fname[dot + 1:]
print(get_ext(‘hello.py’))
def get_ext(fname):
dot = fname.rfind(’.’)
if dot == -1:
return’’
else:
return fname[dot + 1:]
print(get_ext(‘hello.py’))
theres issues with the indentation however when i try to edit the code is indented perfectly, unsure why its showing plainly like that without the spaces
Check the following FAQ which covers how to format code on the forums.
Have you check the documentation for details of how .rfind
works and what it returns? If you have a look you’ll find out under what circumstances -1
is returned.
.rfind is the same as .find except the fact that it searches from right to left
ok thanks will look through
It’s under what circumstances might .rfind()
return -1
that you need to hunt down .