I\'m trying to solve this challenge in hackerrank, which asks to convert all lowercase letters to uppercase letters and vice versa.
I attempt it with the following code:
As said in comments and othe answers, strings are immutable.
Try following:
s = input("Enter input: ")
def convert(ss):
# Convert it into list and then change it
newSS = list(ss)
for i,c in enumerate(newSS):
newSS[i] = c.upper() if c.islower() else c.lower()
# Convert list back to string
return ''.join(newSS)
print(s)
print(convert(s))
# Or use string build in method
print (s.swapcase())