How to convert string to Ascii in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to convert string to Ascii in python?

My code getting a hex back in a string format but I want to convert it into Ascii. >>> Print(x) 32 2e 45 >>> Print(type(x)) <Class 'str'> So if I go to online hex to Ascii converter and put 32 2e 45 in I get 2.E which is what I want to get. There is no way for me to get the value of x in a hex format. I only can get it in a string format so I don't know how to convert it to ascii to get 2.E I hope this make sense. Thank you for helping.

6th Oct 2020, 7:44 PM
Karzan
4 Answers
6th Oct 2020, 8:01 PM
Oma Falk
Oma Falk - avatar
+ 5
Here is my solution, done with a comprehension: inp = '32 2e 45' print(''.join([chr(int(i,16)) for i in inp.split()])) # result: 2.E
6th Oct 2020, 8:50 PM
Lothar
Lothar - avatar
+ 2
Lothar more pythonic☺
7th Oct 2020, 6:08 AM
Oma Falk
Oma Falk - avatar
0
Thanks Frogged this worked for me
6th Oct 2020, 8:07 PM
Karzan