There are several ways of doing this:

>>> hex(ord("c"))
'0x63'
>>> format(ord("c"), "x")
'63'
>>> import codecs
>>> codecs.encode(b"c", "hex")
b'63'

On Python 2, you can also use the hex encoding like this (doesn't work on Python 3+):

>>> "c".encode("hex")
'63'
Answer from Sven Marnach on Stack Overflow
🌐
Python.org
discuss.python.org › python help
How to convert character to hexadecimal and back? - Python Help - Discussions on Python.org
March 22, 2023 - I tried to code to convert string to hexdecimal and back for controle as follows: input = 'Україна' table = [] for item in input: table.append(item.encode('utf-8').hex()) output = '' for item in table: output += chr…
Discussions

String to HEX
I've tried .encode, binascii.hexlify, and a few other things. Ok, well, encode was the correct one, so do that. More on reddit.com
🌐 r/learnpython
7
5
September 2, 2024
How do I replace a hex value in a string with something printable?
The next value of the odd character is \x2212. But I’ve never seen anyway to represent a value in hex in a Python string so I can use the .replace() function. This is what I’ve tried: def cleanhtmllist(mylist): r'''Change extended ascii to normal characters... More on discuss.python.org
🌐 discuss.python.org
5
0
May 22, 2024
Python - Converting Hex to INT/CHAR - Stack Overflow
I am having some difficulty changing a hex to an int/char (char preferably). Via the website; http://home2.paulschou.net/tools/xlate/ I enter the hex of C0A80026 into the hex box, in the DEC / CHAR... More on stackoverflow.com
🌐 stackoverflow.com
Converting all chars in a string to ascii hex in python - Stack Overflow
Just looking for python code that can turn all chars from a normal string (all English alphabetic letters) to ascii hex in python. I'm not sure if I'm asking this in the wrong way because I've been More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-hex-function
hex() function in Python - GeeksforGeeks
July 11, 2025 - Example: ... Explanation: hex() function takes that number and converts it into its hexadecimal representation, which is 0xff. The result is stored in res. ... Parameter: x is an integer number (of type int).
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-hex
Python hex() | DigitalOcean
August 3, 2022 - Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
CoenRaets
jsonviewer.ai › python-string-to-hex
Python String to Hex [Explained with Code Examples] - JSON Viewer
July 5, 2023 - Then, we transform this string variable to bytes by using the encode() method, and the outcome is saved in a variable named bytes. The bytes are then translated into a hexadecimal representation using the hex() method, and the output is saved in a variable named hexadecimal.
🌐
IQCode
iqcode.com › code › python › python-char-to-hex
python char to hex Code Example
tmp = "hello world" print("".join(["{:02x}".format(ord(c)) for c in tmp]))
Find elsewhere
🌐
Python Guides
pythonguides.com › convert-string-to-hexadecimal-in-python
How To Convert String To Hex In Python?
April 3, 2025 - If you want more control over the process or need to understand the underlying mechanics, you can convert each character individually using the ord() function to get the Unicode code point, then convert it to hex with the hex() function in Python.
🌐
Delft Stack
delftstack.com › home › howto › python › str to hex python
How to Convert String to Hex in Python | Delft Stack
February 2, 2024 - Converting a string to hexadecimal in Python refers to the process of transforming a sequence of characters into its equivalent representation in the hexadecimal number system.
🌐
Python Forum
python-forum.io › thread-1715.html
how to convert a string to hex
January 22, 2017 - what is the best way to convert a string to hexadecimal? the purpose is to get the character codes to see what is being read in from a file. i already have command line tools that display the file in hexadecimal. i want to match that up with what...
🌐
Linux Hint
linuxhint.com › string-to-hexadecimal-in-python
String to Hexadecimal in Python – Linux Hint
Line 12: We know the in-built hex(n) method accepts the integer value, converting the integer to the hexadecimal string. That’s why we need to convert the string to an integer to pass it into the hex () method.
🌐
Sling Academy
slingacademy.com › article › python-ways-to-convert-a-string-to-a-hexadecimal-value
Python: 3 ways to convert a string to a hexadecimal value - Sling Academy
May 27, 2023 - string = "Sling Academy" hex_value = ''.join([format(ord(char), 'x') for char in string]) print(hex_value) Because we use the same input as other examples in this article, the output won’t be a new thing: ... The advantage of this technique is that can handle non-ASCII characters and is flexible and customizable. The trade-off is that it requires iterating through each character, which may be less efficient for extremely large strings. Next Article: Python: 4 Ways to Generate Random Strings
🌐
Quora
quora.com › What-is-the-process-for-converting-text-to-hexadecimal-and-vice-versa-in-Python
What is the process for converting text to hexadecimal and vice versa in Python? - Quora
Answer: original_text = "Hello, World!" # to convert from text to hexadecimal hex_representation = original_text.encode().hex() # to convert from hexadecimal to text converted_text = bytes.fromhex(hex_representation).decode() In this code I am not defining the encoding explicitly if not defi...
🌐
Python.org
discuss.python.org › python help
How do I replace a hex value in a string with something printable? - Python Help - Discussions on Python.org
May 22, 2024 - I have Python 3.11 on Windows 10. I’m still fairly new to Python. I have a string with data I got from a website. The website uses an extended ascii character for the minus sign and I’d like to change that to a normal printable dash. The next value of the odd character is \x2212.
🌐
Vultr Docs
docs.vultr.com › python › built-in › hex()
Python hex() - Convert Integer to Hexadecimal
November 25, 2024 - This code demonstrates how to display ... useful when you need to print an integer as a hex string in Python without the 0x prefix. Convert the integer to hexadecimal. Use string manipulation to ensure all characters are uppercase....
🌐
Javatpoint
javatpoint.com › how-to-convert-hex-to-ascii-in-python
How to convert Hex to ASCII in python - Javatpoint
How to convert Hex to ASCII in python with tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, etc.