zer0uno
zer0uno

Reputation: 8030

String and hexadecimal representation

I'm trying the following:

>>> a = '\01'
>>> a
>>> '\x01'
>>> b = '\11'
>>> b
>>> '\t'
>>> c = '\21'
>>> c
>>> '\x11'

I don't understand why sometimes I get hexadecimal representation and other times not.
In '\xhh' the 'x' is fundamental or not?

Upvotes: 0

Views: 790

Answers (2)

Abhijit
Abhijit

Reputation: 63737

Short Answer

You see the hexadecimal representation for those characters for which your native code page cannot represent your characters

Long Answer

Assuming you are using windows, and your default code page is cp1252, '\01' is a non-printable character, an ascii control code, which stands for Start of Heading. As there is no known printable representation of the character, a hexadecimal value is used to display the value.

Upvotes: 5

geert3
geert3

Reputation: 7331

The numbers \11, \21 are OCTAL numbers. \11 octal is \x09 (hex) is equal to '\t' (tab char). \21 octal is \x11 hex is 17 decimal.

Upvotes: 1

Related Questions