Home python how the xa0 character differs from a simple space

how the \ xa0 character differs from a simple space




Well, let’s say we have such examples (in python)


print (repr ("& nbsp;")) (if you copy this example through the question preview, then \ xa0 will be replaced by a space, and if through the editor (edit), it will not be replaced)


print (repr (""))

In fact, they are no different, but in the first character \ xa0, and in the second a space.

So what is this symbol? Why is it needed?

Answer 1, authority 100%

These are different characters:

& gt; & gt; & gt; import unicodedata
& gt; & gt; & gt; unicodedata.name ("\ xa0")
& gt; & gt; & gt; unicodedata.name ("\ x20")

The purpose of NO-BREAK SPACE (non-breaking space ) to prevent automatic line breaks from appearing in its place.

Non-printable characters are escaped in repr, so NO-BREAK SPACE becomes \ xa0, but normal SPACE remains as it is:

& gt; & gt; & gt; "\ x20" .isprintable () # SPACE
& gt; & gt; & gt; "\ xa0" .isprintable ()

Answer 2, authority 50%

\ xa0 is non-breaking space .

The difference is described in wiki :

A computer text encoding element displayed inside a string
like a regular space, but does not allow display programs and
print to break the line at this point. Used for automation
layout, the rules of which prescribe to avoid line breaks in
known cases (mostly for readability).

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions