faint... The string comes with swapcase method to learn about
0 Answer
Method 1: for loop through
content = "heLLo woRlD!"
result = []
for word in content:
# 判断是小写字母
if ord(word) in range(97,123):
result.append(word.upper())
# 判断是大写字母
elif ord(word) in range(65,91):
result.append(word.lower())
else:
result.append(word)
print(''.join(result))
Method 2: Call the string built-in method directly
content = "heLLo woRlD!"
print(content.swapcase())
If it helps, please click to accept ~
这家伙很懒,什么都没留下...