Python字符串|交换箱()
字符串swapcase() 方法将给定字符串的所有大写字符转换为小写,反之亦然,并返回它。
句法:
string_name.swapcase()
Here string_name is the string whose cases are to be swapped.
参数: swapcase() 方法不带任何参数。
返回值:
The swapcase() method returns a string with all the cases changed.
下面是 swapcase() 方法的Python实现
# Python program to demonstrate the use of
# swapcase() method
string = "gEEksFORgeeks"
# prints after swappong all cases
print(string.swapcase())
string = "striver"
print(string.swapcase())
输出:
GeeKSforGEEKS
STRIVER