I'm trying to create a byte string, but it seems to be just a regular character string. What am I doing wrong here?
byteStr = b'some string'
byteStr #'some string'
utfStr = 'some string'.encode('utf-8')
utfStr #'some string'
byteStr == utfStr #True
I'm trying to create a byte string, but it seems to be just a regular character string. What am I doing wrong here?
byteStr = b'some string'
byteStr #'some string'
utfStr = 'some string'.encode('utf-8')
utfStr #'some string'
byteStr == utfStr #True
If you're trying to create a byte array in Python 2, it's called a bytearray
. Python 2 does not have a byte string
.. The b
in front of the str is ignored in Python 2, meaning 'hello' == b'hello'
Try this:
>>> f = b'f'
>>> type(f)
<type 'str'>
Now, it's important to remember that u'f' == 'f'
:
>>> h = u'f'
>>> f == h
True
>>> type(h)
>>> <type 'unicode'>