isupper(), islower(), lower(), upper() in Python and their applications (original) (raw)
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() Method
The **isupper() method checks whether all the characters in a string are uppercase.
**For example:
**Input: string = 'GEEKSFORGEEKS'
**Output: True
Syntax of isupper()
string.isupper()
**Parameters:
- isupper() does not take any parameters
**Return Type:
- **True if all alphabetic characters are uppercase.
- **False otherwise.
**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:
**Input: string = 'geeksforgeeks'
**Output: True
Syntax of islower()
string.islower()
**Parameters:
- islower() does not take any parameters
**Return Type:
- **True if all alphabetic characters are lowercase.
- **False otherwise.
**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:
**Input: string = 'GEEKSFORGEEKS'
**Output: geeksforgeeks
Syntax of lower()
**Syntax: string.lower()
**Parameters:
- lower() does not take any parameters
**Returns: A new string in all lowercase.
**Example:
Python `
s = 'GEEKSFORGEEKS' print(s.lower())
s = 'GeeksforGeeks' print(s.lower())
`
Output
geeksforgeeks geeksforgeeks
Note: Digits and symbols remain unchanged
4. upper() Method
The upper() method returns a copy of the string with all lowercase characters converted to uppercase.
**For example:
**Input: string = 'geeksforgeeks'
**Output: GEEKSFORGEEKS
Syntax of upper()
string.upper()
**Parameters:
- upper() does not take any parameters
**Returns: A new string in all uppercase.
**Example:
Python `
s = 'geeksforgeeks' print(s.upper())
s = 'My name is Prajjwal' print(s.upper())
`
Output
GEEKSFORGEEKS MY NAME IS PRAJJWAL
Application: 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)
`
Output
In original String: Uppercase - 4 Lowercase - 41 Spaces - 7 After changing cases: gEEKSFORgEEKS IS A COMPUTER sCIENCE PORTAL FOR gEEKS
**Related article: