Python has wide range of function for string handling. some ways of string handling are to convert a string to lowercase, uppercase and title case using lower(), upper() & title() function respectively. The other ways of handling strings is to check whether the string is in lowercase using islower() function , whether the string is in uppercase or title case using isupper() and istitle() function.
- lower() Function in python converts the input string to lowercase
- upper() Function in python converts the input string to uppercase
- title() Function in python converts the input string to proper case or title case. that is, all words begin with uppercase and the rest are lowercase.
- islower() Function in python checks whether the input string is in lowercase
- isupper() Function in python checks whether the input string is in uppercase
- istitle() Function in python checks whether the input string is in title case
Syntax of lower() Function in python
Example of lower() Function in python
lower() Function in python converts the input string to lower case
''' convert text to lower case ''' str = "SALUTE to the Mother EARTH"; str.lower()
so the output will be in lowercase as shown below.
NOTE:
- lower() function does not take any arguments, Therefore, It returns an error if a parameter is passed.
- Digits and symbols are returned as it is, Only text string is converted to lowercase.
Syntax of upper() Function in python
Example of upper() Function in python
upper() Function in python converts the input string to upper case
''' convert text to upper case ''' str = "SALUTE to the Mother EARTH"; str.upper()
so the output will be in uppercase as shown below.
Note:
- upper() function does not take any arguments, Therefore, It returns an error if a parameter is passed.
- Digits and symbols are returned as it is, Only text string is converted to uppercase.
Syntax of title() Function in python
Example of title() Function in python
- title() Function in python converts the input string to Proper case or title case. i.e. , all words begin with uppercase and the rest are lowercase.
''' convert text to proper case ''' str = "SALUTE to the Mother EARTH"; str.title()
so the output will be in proper case or title case as shown below.
islower(), isupper() & istitle() function in python
Syntax for isupper() Function in Python:
1.True- If all characters in the string are upper. 2.False- If the string contains 1 or more non-uppercase characters.
Example of isupper() Function in python:
str1 = " 2018 IS AT DOORSTEP"; str1.isupper() str1="Beauty of DEMOCRACY" str1.isupper()
so the output will be
some more examples: below are some more examples for isupper() function
False
False
False
False
False
False
False
False
True
Syntax for islower() Function in Python:
1.True- If all characters in the string are lower. 2.False- If the string contains 1 or more non-lowercase characters.
Example of islower() Function in python:
str1 = "2018 is at doorstep"; str1.islower() str1="Beauty of DEMOCRACY" str1.islower()
so the output will be
some more examples: below are some more examples for islower() function
False
True
True
False
False
True
False
False
False
Syntax for istitle() Function in Python:
1.True- If all words in the string are starting with uppercase. 2.False- If 1 or more words of the string starts with non-uppercase.
Example of istitle() Function in python:
str1 = " 2018 IS AT DOORSTEP"; str1.istitle() str1="Beauty Of Democracy" str1.istitle()
so the output will be
For further understanding of lower(), upper() & title() – islower(), isupper() & istitle() function in python one can refer the documentation
Other Related Topics
- ljust(),rjust() and center() function in python
- String max() & min() function in python
- lstrip(),rstrip() and strip() function in python
- swapcase() Function in Python
- string split in python
- splitlines() Function in Python
- zfill() Function in Python
- startswith() Function in Python
- Extract first n characters from left of column in pandas python
- Extract last n characters from right of the column in pandas python
- Replace a substring of a column in pandas python