if you want to check string end, better use
Alternative approach is using something like
Options can be dict in python 3.7 or collections.OrderedDict (in version before that) in order to preserve the order in which will be checked
some_string.endswith(search_string)
. in checks for membership, so it will return True
even if the search_string
is in the middle of some_string
. .endswith() is also recommened by PEP8 compared to using slicing.Alternative approach is using something like
def spam(): print('Doing something within spam()') def eggs(): print('Doing something within eggs()') options = (('gifv', spam), ('gif', eggs)) some_string = 'foo.gifv' for end, func in options: if some_string.endswith(end): func() breakThis way it will allow to expand the list of options without ending with monstrous if/elif/elif/.../else block.
Options can be dict in python 3.7 or collections.OrderedDict (in version before that) in order to preserve the order in which will be checked
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs