How would I delete everything after a certain character of a string in python? For example I have a string containing a file path and some extra characters. How would I delete e
Use slices:
s = 'test.zip.xyz' s[:s.index('.zip') + len('.zip')] => 'test.zip'
And it's easy to pack the above in a little helper function:
def removeAfter(string, suffix): return string[:string.index(suffix) + len(suffix)] removeAfter('test.zip.xyz', '.zip') => 'test.zip'