Python String swapcase() Method
The swapcase()
method returns a copy of the string with uppercase characters converted to lowercase and vice versa.
Symbols and letters are ignored.
Syntax:
str.swapcase()
Parameters:
None.
Return Value:
Returns a string.
The following example demonstrates the swapcase()
method.
>>> 'hello world'.swapcase()
'HELLO WORLD'
>>> 'Hello World'.swapcase()
'hELLO wORLD''
>>> 'HeLLo WoRld'.swapcase()
'hEllO wOrLD'
A string can contain a mix of upper and lower case characters. All cases will be reversed when swapcase()
method is called.
The swapcase()
method ignores symbols and numbers, as shown below.
>>> '#1 Harbor Side'.swapcase()
'#1 hARBOR sIDE'
>>> ''123456'.swapcase()
'123456'