I have a string b'helloworld\n'. I want to extract helloworld from it. For this, I am doing
print(string[1:-2])
But on output I am getting b'elloworl'.
How can I extraxt helloworld.
Thanks
From this link, to change binary string to normal string use this:
>>> b'helloworld\n'.decode('ascii') # you can use utf8 or something else, it is up to you
'helloworld\n'
To delete whitespaces use strip():
>>> b'helloworld\n'.decode('ascii').strip()
'helloworld'
string[0:-1].b'helloworld'bin front of string is a string literal which means string would of bytes type instead ofstrtype and don't impact literal meaning of the string. See docs.python.org/3.3/reference/… for more info.string.decode("utf-8")