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
Updated on 30-Sep-2019 06:36:15

Advertisements