file = open("sample.bin", "wb") COPYfile.write(b"This binary string will be written to sample.bin") COPYfile.close()
Here is what the above code is Doing:
1. We open a file called sample.bin in write binary mode.
2. We write a binary string to the file.
3. We close the file.