Coming from a socket it will always be
Can also do it like and only convert when needed.
so in background is really doing this when use
bytes
,can easily convert to string str
type.>>> data = b'/hello123/' >>> type(data) <class 'bytes'> >>> >>> data = data.decode() >>> type(data) <class 'str'> >>> data '/hello123/' >>> data.strip('/') 'hello123'When the change from Python 2 to Python 3 happened they made a clear choice that bytes and string(Unicode) can not mix.
Can also do it like and only convert when needed.
>>> data = b'hello123/' >>> type(data) <class 'bytes'> >>> data.strip(b'/') b'hello123'When convert to
str
it will be Unicode as all string in Python3 is that,so in background is really doing this when use
.decode()
data = data.decode('utf-8')