You are looking for the chr function.

You seem to be mixing decimal representations of integers and hex representations of integers, so it's not entirely clear what you need. Based on the description you gave, I think one of these snippets shows what you want.

>>> chr(0x65) == '\x65'
True


>>> hex(65)
'0x41'
>>> chr(65) == '\x41'
True

Note that this is quite different from a string containing an integer as hex. If that is what you want, use the hex builtin.

Answer from Mike Graham on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_func_hex.asp
Python hex() Function
Python Examples Python Compiler ... Plan Python Interview Q&A Python Training ... The hex() function converts the specified number into a hexadecimal value....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-hex-function
hex() function in Python - GeeksforGeeks
July 11, 2025 - hex() function in Python is used to convert an integer to its hexadecimal equivalent. It takes an integer as input and returns a string representing the number in hexadecimal format, starting with "0x" to indicate that it's in base-16.
Discussions

Add length parameter to hex
Hey everyone! During my wrok I need to convert int to hex and send it to a server. The problem is that data I send must be paired. To achieve this I write code like this: value_to_send = hex(value)[2:] if len(value_to_send) % 2: value_to_send = '0' + value_to_send My suggestion is to add optional ... More on discuss.python.org
🌐 discuss.python.org
3
0
April 23, 2023
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
Hex string variable to hex value conversion in python - Stack Overflow
I have a variable call hex_string. The value could be '01234567'. Now I would like to get a hex value from this variable which is 0x01234567 instead of string type. The value of this variable may c... More on stackoverflow.com
🌐 stackoverflow.com
How to convert character to hexadecimal and back?
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(int(item, 16)) print(output) To my surprise the output is total different ... More on discuss.python.org
🌐 discuss.python.org
6
0
March 22, 2023
🌐
Hex Technologies
learn.hex.tech › analyze & build › python cells
Python cells | Learn | Hex Technologies
Users can edit and execute any valid Python in a Python cell. Hex projects come pre-installed with a number of Python packages, which you can view in the Environment tab of the left sidebar.
🌐
Python.org
discuss.python.org › python help
Add length parameter to hex - Python Help - Discussions on Python.org
April 23, 2023 - Hey everyone! During my wrok I need to convert int to hex and send it to a server. The problem is that data I send must be paired. To achieve this I write code like this: value_to_send = hex(value)[2:] if len(value_to_send) % 2: value_to_send = '0' + value_to_send My suggestion is to add optional parameter in hex() to automatically pad output with 0 Signature will be changed to def hex(value, length: int | None = None) -> str: pass You would use it like so: >>> hex(13) # 0xd >>> hex...
Find elsewhere
🌐
Python
docs.python.org › 3 › builtins › stdtypes.html
Built-in Types — Python 3.14.8 documentation
Numbers are created by numeric literals or as the result of built-in functions and operators. Unadorned integer literals (including hex, octal and binary numbers) yield integers. Numeric literals containing a decimal point or an exponent sign yield floating-point numbers.
🌐
YouTube
youtube.com › watch
Python 3 hex() built-in function TUTORIAL - YouTube
Tutorial on how to use the hex() built-in function from the Python 3 Standard Library.📖 You can check out the Udemy course (Python Built-in Functions) here:...
Published: June 2, 2019
🌐
Real Python
realpython.com › ref › builtin-functions › hex
hex() | Python’s Built-in Functions – Real Python
The built-in hex() function converts a given integer into its lowercase hexadecimal representation.
🌐
Quora
quora.com › In-Python-how-do-I-use-hex-value-to-print-a-hexadecimal-String-with-0-s-padded-to-the-left-and-without-0X-in-front
In Python: how do I use hex (value) to print a hexadecimal String with 0’s padded to the left and without “0X” in front? - Quora
Answer (1 of 4): Lukas has already given you an excellent answer, but, for completeness, I feel obliged to point out that you can print hex in a somewhat more flexible way using str.format() as below where the 0 is the fill character, 6 is the field width and X says you want hex format in upperca...
🌐
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…
🌐
Python
docs.python.org › 3 › builtins › functions.html
Built-in Functions — Python 3.14.8 documentation
To obtain a hexadecimal string representation for a float, use the float.hex() method.
🌐
Hex-Rays
hex-rays.com › ida-free
IDA Free: Disassembler & Decompiler at No Cost
Free disassembler and decompiler to learn reverse engineering. Core IDA features at no cost for students and non-commercial use. Download and start today.
🌐
PREP INSTA
prepinsta.com › home › python tutorial › hex() function in python programming language
hex() function in Python programming language | PrepInsta
September 7, 2023 - hex() function in Python programming language is used to convert numbers of different bases into the numebr of base 16 or hexadecimal number
🌐
Vultr Docs
docs.vultr.com › python › built-in › hex()
Python hex() - Convert Integer to Hexadecimal
November 25, 2024 - The hex() function in Python is a built-in method used to convert an integer into its corresponding hexadecimal string. This function is particularly useful in fields like cryptography, computer science education, or any scenario where hexadecimal ...
🌐
w3resource
w3resource.com › python › built-in-function › hex.php
Python hex() function - w3resource
April 18, 2026 - Python hex() function: The hex() function converts an integer number to a lowercase hexadecimal string prefixed with 0x.