Computer >> Computer tutorials >  >> Programming >> Python

How to invert case for all letters in a string in Python?


String class has a method called swapcase() for swapping case of all letters. You can use it as follows:

>>> 'Hello World 123'.swapcase()
'hELLO wORLD 123'
>>> 'Make America Great Again'.swapcase()
'mAKE aMERICA gREAT aGAIN'