I feel Martijn Pieter's comment deserves to be highlighted as an answer:
binary_string = format(value, '0{}b'.format(width))
To me is is both clear and versatile.
I feel Martijn Pieter's comment deserves to be highlighted as an answer:
binary_string = format(value, '0{}b'.format(width))
To me is is both clear and versatile.