Last Updated : 03 May, 2025
Python provides several built-in string methods to work with the case of characters. Among them, isupper(), islower(), upper() and lower() are commonly used for checking or converting character cases. In this article we will learn and explore these methods:
1. isupper() MethodThe isupper() method checks whether all the characters in a string are uppercase.
For example:
Syntax of isupper()Input: string = 'GEEKSFORGEEKS'
Output: True
string.isupper()
Parameters:
Return Type:
Example:
Python
s = 'GEEKSFORGEEKS'
print(s.isupper())
s = 'GeeksforGeeks'
print(s.isupper())
2. islower() Method
The islower() method checks whether all the characters in a string are lowercase.
For example:
Syntax of islower()Input: string = 'geeksforgeeks'
Output: True
string.islower()
Parameters:
Return Type:
Example:
Python
s = 'geeksforgeeks'
print(s.islower())
s = 'GeeksforGeeks'
print(s.islower())
3. lower() Method
The lower() method returns a copy of the string with all uppercase characters converted to lowercase.
For example:
Syntax of lower()Input: string = 'GEEKSFORGEEKS'
Output: geeksforgeeks
Syntax: string.lower()
Parameters:
Returns: A new string in all lowercase.
Example:
Python
s = 'GEEKSFORGEEKS'
print(s.lower())
s = 'GeeksforGeeks'
print(s.lower())
geeksforgeeks geeksforgeeks
4. upper() MethodNote: Digits and symbols remain unchanged
The upper() method returns a copy of the string with all lowercase characters converted to uppercase.
For example:
Syntax of upper()Input: string = 'geeksforgeeks'
Output: GEEKSFORGEEKS
string.upper()
Parameters:
Returns: A new string in all uppercase.
Example:
Python
s = 'geeksforgeeks'
print(s.upper())
s = 'My name is Prajjwal'
print(s.upper())
GEEKSFORGEEKS MY NAME IS PRAJJWALApplication: Count Uppercase, Lowercase Letters and Spaces
In this example we will count the number of uppercase, lowercase and space characters and toggle the case of each character of a string.
Python
s = 'GeeksforGeeks is a computer Science portal for Geeks'
ns = ''
cu = 0
cl = 0
cs = 0
for ch in s:
if ch.isupper():
cu += 1
ns += ch.lower()
elif ch.islower():
cl += 1
ns += ch.upper()
elif ch.isspace():
cs += 1
ns += ch
print("In original String:")
print("Uppercase -", cu)
print("Lowercase -", cl)
print("Spaces -", cs)
print("After changing cases:")
print(ns)
In original String: Uppercase - 4 Lowercase - 41 Spaces - 7 After changing cases: gEEKSFORgEEKS IS A COMPUTER sCIENCE PORTAL FOR gEEKS
Related article:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4