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
🌐
Vultr Docs
docs.vultr.com β€Ί python β€Ί built-in β€Ί hex
Python hex() - Convert Integer to Hexadecimal | Vultr Docs
November 25, 2024 - This method is particularly useful when processing hexadecimal input or decoding hexadecimal representations back to their integer form. The hex() function in Python provides a straightforward way to convert integers to their hexadecimal ...
🌐
Programiz
programiz.com β€Ί python-programming β€Ί methods β€Ί built-in β€Ί hex
Python hex()
The hex() function converts an integer number to the corresponding hexadecimal string.
🌐
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.
🌐
Medium
medium.com β€Ί @whyamit404 β€Ί how-to-convert-an-int-to-a-hex-string-bf910545b3e8
How to Convert an Int to a Hex String? | by whyamit404 | Medium
February 8, 2025 - Simply put, the hex() function helps you take a regular integer (like 10 or 255) and transform it into its hexadecimal string counterpart. For instance, the number 255 becomes '0xff', where the 0x at the start indicates it’s a hexadecimal number.
🌐
DigitalOcean
digitalocean.com β€Ί community β€Ί tutorials β€Ί python-hex
Python hex() | DigitalOcean
August 3, 2022 - Python hex() function is used to convert an integer to a lowercase hexadecimal string prefixed with β€œ0x”. We can also pass an object to hex() function, in that case the object must have __index__() function defined that returns integer. The input integer argument can be in any base such ...
🌐
LabEx
labex.io β€Ί tutorials β€Ί python-how-to-format-the-hexadecimal-output-in-python-417964
How to format the hexadecimal output in Python | LabEx
As you can see, when converting a decimal to hexadecimal using the hex() function, Python returns a string with the 0x prefix. This is the standard representation of hexadecimal numbers in many programming languages.
🌐
Data Science Parichay
datascienceparichay.com β€Ί home β€Ί blog β€Ί python – convert integer to hexadecimal
Python - Convert Integer to Hexadecimal - Data Science Parichay
March 13, 2022 - You can use the Python built-in hex() function to convert an integer to its hexadecimal form in Python. Pass the integer as an argument to the function.
Find elsewhere
🌐
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
You can convert from the characters to integers, do the math, and then convert the resulting integers back to characters. Python has int ( ) and hex ( ) functions for this. Or you can use look-up tables: a list of (character, integer) or (integer, character) pairs.
🌐
Java2Blog
java2blog.com β€Ί home β€Ί python β€Ί print int as hex in python
Print int as hex in Python [3 ways] - Java2Blog
November 27, 2023 - The "x" in {number:x} specifies hexadecimal formatting, producing "ff". ... F-strings are efficient and highly readable, often offering better performance than traditional formatting methods. Below is a Python script that uses the timeit module to compare the performance of different methods for converting an integer to a hexadecimal string, both with and without the 0x prefix.
🌐
W3Schools
w3schools.com β€Ί python β€Ί ref_func_hex.asp
Python hex() Function
Python Bootcamp Python Certificate Python Training ... The hex() function converts the specified number into a hexadecimal value. The returned string always starts with the prefix 0x.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί convert-hex-string-to-integer-in-python
Convert Hex String To Integer in Python - GeeksforGeeks
July 23, 2025 - The resulting `decimal_integer` is 64034. ... In this example, the hexadecimal string "0xfe00" is converted to an integer using the `literal_eval()` function from the `ast` module.
🌐
w3resource
w3resource.com β€Ί python β€Ί built-in-function β€Ί hex.php
Python hex() function - w3resource
September 20, 2024 - Python hex() function: The hex() function converts an integer number to a lowercase hexadecimal string prefixed with 0x.
🌐
Finxter
blog.finxter.com β€Ί python-integer-to-hex-the-ultimate-guide
Python Integer to Hex β€” The Ultimate Guide – Be on the Right Side of Change
You can choose the method that best suits your needs and is compatible with your version of Python. Converting negative integers and zero to their corresponding hexadecimal representation in Python can be achieved using the hex() function, which produces a string output prefixed with '0x' for ...
🌐
Appdividend
appdividend.com β€Ί python-hex
Python hex(): Converting an Integer to Hex
September 4, 2025 - Python hex() function converts an integer number into a lowercase hexadecimal string prefixed with '0x' (or '-0x' for negative values).
🌐
Sololearn
sololearn.com β€Ί en β€Ί Discuss β€Ί 2354263 β€Ί how-to-convert-any-integer-number-to-hexadecimal-number
How to convert any integer number to hexadecimal number? | Sololearn: Learn to code for FREE!
print(hex(255)) # output 0xff print(int("ff", 16)) # output 255 or using input(): print(hex(int(input()))) print(int(input(), 16)) # inputting ff or 0xff gives same result ... In python, Hex numbers can also be created for output with print() ...
🌐
Note.nkmk.me
note.nkmk.me β€Ί home β€Ί python
Convert Binary, Octal, Decimal, and Hexadecimal in Python | note.nkmk.me
May 19, 2023 - For example, use 0b1111 (= 0xf) for 4-bit, 0xff for 8-bit, and 0xffff for 16-bit representations. ... You can use the built-in function int() to convert a binary, octal, or hexadecimal string into a number.
🌐
Educative
educative.io β€Ί answers β€Ί how-to-convert-a-decimal-number-to-hexadecimal-in-python
How to convert a decimal number to hexadecimal in Python
Line 4–5: The function starts with a special case: if the input decimal_num is 0, it directly returns β€œ0” since the hexadecimal representation of 0 is β€œ0”. Line 8–13: Inside the while loop, the decimal number is continuously divided by 16, and the remainder is used to index into the hex_characters string to get the corresponding hexadecimal digit.
🌐
Finxter
blog.finxter.com β€Ί home β€Ί learn python blog β€Ί python integer to hex string (easy)
Python Integer to Hex String (Easy) - Be on the Right Side of Change
November 16, 2022 - The easiest way to convert a decimal integer number x to a hexadecimal string is to use the built-in Python function hex(x).
🌐
W3docs
w3docs.com β€Ί python
Convert hex string to integer in Python
The int() function takes two arguments: the first is the hex string, and the second is the base of the number system used in the string (base 16 for hex). ... You can also use the int.from_bytes() function to convert hex string to integer by ...