0

I have this string s = 'ha\xcc\x81nh'. I want to use as byte, is there anything as b'{s}' like f string f'{s}'

mk7120
  • 1
  • 1
    Would this question help you out? https://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3 – Anil Feb 23 '21 at 03:56

1 Answers1

2

Normally we can use the following code to convert a string to a byte string.

b = sample_string.encode()

If we use this method in your use-case it would be like this.

b = f'{s}'.encode()
Nuran
  • 331
  • 3
  • 14