bytes.isupper() returns True if the bytes contain at least one ASCII uppercase letter and no ASCII lowercase letters. Digits, spaces, punctuation, and bytes 128-255 are ignored.
Many text protocols write keywords in capitals, such as USER, PASS, and QUIT in FTP. isupper() helps tell those keywords apart from user data.
bytes.isupper() is a method of the built-in bytes type: call it on a bytes object with dot notation, such as data.isupper(...). No import is needed, and bytearray objects have the same method.
Syntax
No arguments; returns a bool.
python
result = data.isupper()
Call
What it does
b"HTTP/1.1".isupper()
Returns True.
b"Error".isupper()
Returns False.
b"42".isupper()
Returns False: no letters.
isupper() and islower() can both be False, for mixed case or for data without letters, but never both True.
Method signatures
python
bytes.isupper()
# returns True or False; bytearray.isupper() works the same way
Parameters
isupper() takes no parameters.
Return Value
Return Value
Description
True
At least one ASCII uppercase letter and no ASCII lowercase letters.
False
Any lowercase letter, or no ASCII letters at all.
Python Examples
Example 1 — Uppercase Checks with Digits and Symbols
Check a protocol version, an error code, a mixed-case word, a number, and empty bytes.
python
for s in [b"HTTP/1.1", b"ERROR 42", b"Error", b"42", b""]:
print(s, s.isupper())