How to use 'python remove substring from string' in Python

Every line of 'python remove substring from string' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
29def test_you_can_get_a_substring_from_a_string(self):
30 string = "Bacon, lettuce and tomato"
31 self.assertEqual('let', string[7:10])
56def stripper(string, substring, direction='right'):
57 done = False
58 strippedString = ''
59 if direction == 'right':
60 string = string[::-1]
61 for char in string:
62 if char == substring and not done:
63 done = True
64 else:
65 strippedString += char
66 if direction == 'right':
67 strippedString = strippedString[::-1]
68 return strippedString

Related snippets