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

PythonServer Side ProgrammingProgramming

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'
raja
Published on 12-Dec-2017 12:37:03
Advertisements