Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python character with hex value

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 number 48 and 46 are assigned to H and F respectively:

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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 ~
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading