0

I'm a Python noob. I was reading through some documentation and I came across something that baffled me.

What is the difference between Byte strings and Unicode strings in python? Especially in terms of what is being inputed and the output.

Please explain using the simplest terms possible

N.B : I use python 3.x

1 Answers1

0

I searched around and found that byte strings can only contain byte characters, which exclude punctuation marks and other unicode characters. Unicode strings can contain, well, all unicode characters.

In python 2.x, byte strings are written much like ordinary strings while unicode strings have a prefixed "u".

a = 'foobar'    (byte string)
b = u'foo-bar'    (unicode string)

It's written the opposite way for python 3.x

a = b'foobar'    (byte string)
b = 'foo-bar'    (unicode string)