Python Glossary Русский

all Python 3Byte sequencesfunction

bytes.isupper

bytes — is* checks

Check that all cased bytes are upper-case.

Syntax

b.isupper(...)

The method does not ask "are there no lower-case letters" but "is there at least one cased letter and are they all upper-case" — which is why b'123' and b'' both give False, and the isupper()/islower() pair does not cover every input. Casing is strictly ASCII here: non-ASCII bytes (Cyrillic in UTF-8, say) are not letters at all, so check the case of such text only after decode().

Examples

print(b'ABC'.isupper())   # → True
print(b'ABC1!'.isupper())   # → True
print(b'Abc'.isupper())   # → False
print(b'123'.isupper())   # → False
print(b''.isupper())   # → False
print(b'abc'.upper())   # → b'ABC'

See also

Open in the full glossarydocs.python.orgReport an inaccuracy