There are 4 methods in Python that works with case of a string.
Below are methods that works with case of a string
- upper()
- lower()
- swapcase()
- title()
upper() method
This method is use to convert all characters in a string into uppercase or capital letters.
In the below examples all characters in a string is converted into uppercase
>>> str = 'Python is a popular programming language'
>>> str.upper()
'PYTHON IS A POPULAR PROGRAMMING LANGUAGE'
>>> str1 = 'PyThon LAnGuAgE'
>>> str1.upper()
'PYTHON LANGUAGE'
lower() method
This method is use to convert all characters in a string into lower case or small letters.
>>> name = 'roHan jadHaV'
>>> name.lower()
'rohan jadhav'
swapcase() method
This method converts uppercase into lowercase and vice versa.
Below are the examples of swapcase().
Below are the examples of swapcase().
>>> city = 'LondoN'
>>> city.swapcase()
'lONDOn'
>>> country = 'UnITed STateS'
>>> country.swapcase()
'uNitED stATEs'
title() method
This method convert first character of each word in a string in uppercase and remaining characters in lowercase. Below are the examples.
>>> a = 'this is the examaple 1'
>>> a.title()
'This Is The Examaple 1'
>>> b = 'this is second example'
>>> b.title()
'This Is Second Example'