Python character with hex value

Question:

Python have an escape sequence in which x is there and if we write two integers after x and print it, it gives us a character for e.g- print("x48") gives us letter H. I want a list that shows which number is assigned to which character.

The hexadecimal numbers 48 and 46 are assigned to H and F respectively:

print("x48")
print("x46")

I want list of all numbers that are assigned to their respective character.

Asked By: Anubhav

||

Answers:

Use hex and chr

print("Dec Hex Char")
for c in range(32,127):
    print(c, hex(c), chr(c))

Output is:

Dec Hex Char
32 0x20  
33 0x21 !
34 0x22 "
35 0x23 #
36 0x24 $
37 0x25 %
38 0x26 &
39 0x27 '
40 0x28 (
41 0x29 )
42 0x2a *
43 0x2b +
44 0x2c ,
45 0x2d -
46 0x2e .
47 0x2f /
48 0x30 0

etc, to

119 0x77 w
120 0x78 x
121 0x79 y
122 0x7a z
123 0x7b {
124 0x7c |
125 0x7d }
126 0x7e ~
Answered By: ProfDFrancis
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.