1>>> st = "hello world"
2>>> ' '.join(format(ord(x), 'b') for x in st)
3'1101000 1100101 1101100 1101100 1101111 100000 1110111 1101111 1110010 1101100 1100100'
4
5#using `bytearray`
6>>> ' '.join(format(x, 'b') for x in bytearray(st, 'utf-8'))
7'1101000 1100101 1101100 1101100 1101111 100000 1110111 1101111 1110010 1101100 1100100'