This is because strings are immutable . You cannot change them locally.
Therefore, you should overwrite the value of the variable as follows:
self.val = self.val.lower()
Note. Unless, of course, your self.val not a string, but rather some mutable object that changes in place after the lower() method is called. But this is not the case (you can do it if you created the self.val class, though).
An example of a mutable object with the lower() method changing it in place:
>>> class LowerableList(list): def lower(self): for i, item in enumerate(self): self[i] = item.lower() >>> a = LowerableList(['A', 'a', 'X', 'D']) >>> a ['A', 'a', 'X', 'D'] >>> a.lower() >>> a ['a', 'a', 'x', 'd']
Does it help?
source share