We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
for i in s:
if i.isupper():
i = i.lower()
new_string = new_string + i
elif i.islower():
i = i.upper()
new_string = new_string + i
else:
new_string = new_string + i
return new_string
By using swapcase() this problem can be solved with one line of code.
code>> def swap_case(s): ex = s.swapcase() return ex
def swap_case(s): new_string = '""
def swap_case(s): s1 = [i.lower() if i.isupper() else i.upper() for i in s] s1= "".join(s1) return s1