String prefix question

Ben Finney ben+python at
Mon Nov 9 04:01:23 CET 2009

Alan Harris-Reid <alan at> writes:

> From what I can gather from the documentation the b prefix represents
> a bytes literal

Yes. In Python 3 there are two types with similar-looking literal
syntax: ‘str’ and ‘bytes’. The types are mutually incompatible (though
they can be explicitly converted).


> but can anyone explain (in simple english) what this means?

It means the difference between “a sequence of bytes” and “a sequence of
characters”. The two are not the same, have not ever been the same
despite a long history in computing of handwaving the differences, and
Python 3 finally makes them unambiguously distinct.

A general solution wasn't even feasible for a long time, but now we have
Unicode, a mature standard for uniformly representing all the world's
writing systems in software. So Python 3 made ‘str’ the Unicode “string
of characters” type, and the ‘'foo'’ literal syntax creates objects of
this type.

The Python 3.1 documentation has a Unicode HOWTO that you should read

 \       “We must respect the other fellow's religion, but only in the |
  `\       sense and to the extent that we respect his theory that his |
_o__)     wife is beautiful and his children smart.” —Henry L. Mencken |
Ben Finney

More information about the Python-list mailing list