python char to hex 1

python char to hex

tmp = "hello world"

print("".join(["{:02x}".format(ord(c)) for c in tmp]))

Here is what the above code is Doing:
1. The first line is a list comprehension. It’s a list of strings, each string is a hex representation of a character in the string “hello world”.
2. The second line is a string, which is the result of joining the list of strings from the first line with an empty string.

Similar Posts