First of all, I know -= operation doesn't work in str
.
But is there a function that works the same?
The reason why I need this is because
def function(self, str_source):
str_source = str_source[:-1] # removing last character of the string
str_source += self.other_function() # adding other characters
return True
In this sort of function, when I do s = s[:-1]
, the original string does not change.
I know why it does not change, and I know I can just return another modified string, but I am currently working on someone else's code that I can't complete rip up the Project.
So is it possible to remove the substring of a string in a function?