UnknownBatman
UnknownBatman

Reputation: 65

How to convert a string into ASCII?

How can I convert a string, say "HELLO", into something like this?

As ASCII string: "72_69_76_76_79".

I tried [ord(c) for c in string], but it returns a list.

I want the result in the form of string

Upvotes: 0

Views: 59

Answers (1)

Moshe perez
Moshe perez

Reputation: 1726

you can use this:

"_".join([str(ord(c)) for c in "HELLO"])

Upvotes: 3

Related Questions