Python String isupper()

Filed Under: Python

Python string isupper()
Python String isupper() function returns True if all the cased characters are in Uppercase. If the string is empty or there are no cased characters then it returns False.

Python String isupper()

Cased characters are those with general category property being one of “Lu” (Letter, uppercase), “Ll” (Letter, lowercase), or “Lt” (Letter, titlecase).

Let’s look at some examples of isupper() function.


s = 'HELLO WORLD'
print(s.isupper())

Output: True because all the cased characters are in Uppercase.


s = 'Hello World'
print(s.isupper())

Output: False because there are some cased characters in lowercase.


s = 'HELLO WORLD 2019'
print(s.isupper())

Output: True because all the cased characters are in Uppercase. The numbers in the string are not cased characters.


s = ''
print(s.isupper())

Output: False because string is empty.


s = '2019'
print(s.isupper())

Output: False because string doesn’t have any cased character.

Let’s look at an example with special characters string.


s = 'ÂƁȻ2019'
print(s.isupper())

Output: True because all the cased characters in the string are in Uppercase.

Print All Uppercase Cased Characters

Here is a simple program to print information about all the Uppercase cased characters.


import unicodedata

count = 0
for codepoint in range(2 ** 16):
    ch = chr(codepoint)
    if ch.isupper():
        print(u'{:04x}: {} ({})'.format(codepoint, ch, unicodedata.name(ch, 'UNNAMED')))
        count = count + 1
print(f'Total Number of Uppercase Unicode Characters = {count}')

Output:


0041: A (LATIN CAPITAL LETTER A)
0042: B (LATIN CAPITAL LETTER B)
0043: C (LATIN CAPITAL LETTER C)
...
ff38: X (FULLWIDTH LATIN CAPITAL LETTER X)
ff39: Y (FULLWIDTH LATIN CAPITAL LETTER Y)
ff3a: Z (FULLWIDTH LATIN CAPITAL LETTER Z)
Total Number of Uppercase Unicode Characters = 1154
If you are not familiar with f-prefixed string formatting, please read f-strings in Python.
You can checkout more Python examples from our GitHub Repository.

Reference: Official Documentation

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages