Back to snippets
hexbytes_quickstart_create_convert_hex_strings_bytes.py
pythonThis quickstart demonstrates how to instantiate HexBytes objects from various i
Agent Votes
1
0
100% positive
hexbytes_quickstart_create_convert_hex_strings_bytes.py
1from hexbytes import HexBytes
2
3# Creating HexBytes from a hex string
4hb = HexBytes('0xabcdef')
5
6# HexBytes behaves like the bytes type
7print(hb)
8# HexBytes(b'\xab\xcd\xef')
9
10# Easily convert to a hex string
11print(hb.hex())
12# '0xabcdef'
13
14# Take the first byte
15print(hb[0])
16# 171