【Python】字符串的大小写
一、题目
You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.
For Example:
Www.HackerRank.com → wWW.hACKERrANK.COM
Pythonist 2 → pYTHONIST 2
Sample Input
HackerRank.com presents "Pythonist 2".
Sample Output
hACKERrANK.COM PRESENTS "pYTHONIST 2".
二、 代码
def swap_case(s):
# 使用字符串的 swapcase() 方法交换大小写
return s.swapcase()
if __name__ == '__main__':
# 读取输入字符串
s = input()
# 调用函数并打印结果
result = swap_case(s)
print(result)
原文地址:https://blog.csdn.net/u010528690/article/details/140622005
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!