pad binary string with a given byte value (python 3)

Peter Otten __peter__ at
Sat Sep 20 14:27:16 CEST 2014

Nagy László Zsolt wrote:

> I can figure out way for example this:
> >>> b'T'+bytearray([32])
> but it just don't seem right to create a list, then convert it to a byte
> array and then convert it to a binary string. What am I missing?

By the way, you can repeat bytes (and strings) by multiplying: 

>>> b"\x01"*3
>>> b"ab"*3

More information about the Python-list mailing list