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

0

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.