PyDocs

Nav

Python Runtime Services

bytes.fromhex

builtins

classmethod of bytes
  • bytes.fromhex(string, /)
Create a bytes object from a string of hexadecimal numbers.

Spaces between two numbers are accepted.
Example: bytes.fromhex('B9 01EF') -> b'\\xb9\\x01\\xef'.
Changed in 3.7, 3.14
  • 3.7: bytes.fromhex() now skips all ASCII whitespace in the string, not just spaces.
  • 3.14: bytes.fromhex() now accepts ASCII bytes and bytes-like objects as input.
1 Example
>>> bytes.fromhex('2Ef0 F1f2  ')
b'.\xf0\xf1\xf2'
from the Python docs
See Also
No see-alsos for builtins/bytes.fromhex
0 Notes
No notes for bytes.fromhex