Python Glossary Русский

all Python 3base64function

base64.b16encode()

Base32 and Base16

Encodes bytes as Base16, hexadecimal with capital letters. The same as bytes.hex().upper(), but as bytes.

Syntax

base64.b16encode(s)

For plain hex output bytes.hex() is usually handier: it returns a str, uses lowercase and supports a separator. b16encode is for places that expect RFC 4648 Base16, uppercase and as bytes. The size doubles, the most wasteful format in the module.

Examples

import base64
print(base64.b16encode(b'\xca\xfe'), b'\xca\xfe'.hex())  # → b'CAFE' cafe

See also

Open in the full glossarydocs.python.orgReport an inaccuracy