binary in string python code example
Example 1: format binary string python
x = 10
print(format(x, '#b')) # 0b1010
print(format(x, 'b')) # 1010
x= 0xF
print(format(x, 'b')) # 1111
print(f'{x:b}') # 1111 (If you knew this format, you are Python Ninja!)
Example 2: python binary to string
testing = "Satana Blabbers".encode() # string to bytes
# now bytes to string
print(testing.decode(), testing.decode('utf-8')) # both are same