What does dot == -1 means in this code? does it mean that if dot is the last character in the string

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 :slight_smile: will look through

It’s under what circumstances might .rfind() return -1 that you need to hunt down :+1:.

1 Like