class test:
def __init__(self, val):
self.val = val
self.val.lower()
Why doesn't lower() operate on the contents of val in this code?
You probably mean:
self.val = self.val.lower()
Or, more concisely:
class test:
def __init__(self, val):
self.val = val.lower()
To elaborate, lower()
doesn't modify the string in place (it can't, since strings are immutable). Instead, it returns a copy of the string, appropriately modified.
The documentation states it pretty clearly:
Return a copy of the string with all the cased characters [4] converted to lowercase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With