So to return a copy of a string converted to lowercase or uppercase one obviously uses the lower() or upper().
But how does one go about making a copy of a string with specific letters converted to upper or lowercase.
For example how would i convert 'test' into 'TesT'
this is honestly baffling me so help is greatly appreciated
got it, thanks for the help Cyber and Matt!
If you're just looking to replace specific letters:
>>> s = "test"
>>> s.replace("t", "T")
'TesT'
There is one obvious solution, slice the string and upper the parts you want:
test = 'test'
test = test[0].upper() + test[1:-1] + test[-1].upper()
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