Python String swapcase() Method
The swapcase()
method returns a new string with all the uppercase letters converted to lowercase and all the lowercase letters converted to uppercase. This method doesn’t modify the original string, it creates and returns a new string with the case swapped.
Syntax
string.swapcase()
Parameters
No parameters
Return Value
Returns a new string with the case of all characters swapped.
Examples
Basic Usage
text = "Hello World"
print(text.swapcase()) # Output: hELLO wORLD
With Non-Alphabetic Characters
Characters that are not letters (e.g., numbers, symbols, and whitespace characters) remain unchanged.
text = "3.14#@"
print(text.swapcase()) # Output: 3.14#@