Just for completeness, using the modern .format() syntax:

>>> numbers = [1, 15, 255]
>>> ''.join('{:02X}'.format(a) for a in numbers)
'010FFF'
Answer from gak on Stack Overflow
🌐
LabEx
labex.io › tutorials › python-how-to-format-the-hexadecimal-output-in-python-417964
How to format the hexadecimal output in Python | LabEx
The lowercase letters (a-f) are the default for Python's hexadecimal output, but you might need uppercase or different formats depending on your application. Let's modify our script to explore some basic formatting options: Add the following code to the hex_formatting.py file: ## Controlling the case (uppercase/lowercase) decimal_value = 171 ## Default (lowercase) hex_lowercase = hex(decimal_value) print(f"\nDefault hex (lowercase): {hex_lowercase}") ## Using string methods to convert to uppercase hex_uppercase = hex(decimal_value).upper() print(f"Hex in uppercase: {hex_uppercase}") ## Removin
Discussions

string - Print a variable in hexadecimal in Python - Stack Overflow
See also: Printing a Python list with hex elements. More on stackoverflow.com
🌐 stackoverflow.com
python - How to print a value as a hex - Stack Overflow
I'm able to read a hexadecimal value from a file and multiply it, but how could I print it out as a hex too. Following prints value as an integer. #!/usr/bin/env python2 f = open('file.dat', 'r') f. More on stackoverflow.com
🌐 stackoverflow.com
python - Print a string as hexadecimal bytes - Stack Overflow
I have this string: Hello, World! and I want to print it using Python as '48:65:6c:6c:6f:2c:20:57:6f:72:6c:64:21'. ... If the idea is to return only 2-digit hex values, then this question implies the use of byte strings (i.e. Python 2 str or Python 3 bytestring), as there is no unequivocal transformation of a character into an integer in 0…255. Thus, character strings (Python 2 unicode and Python 3 str) first require some encoding before being convertible in this hexadecimal format... More on stackoverflow.com
🌐 stackoverflow.com
Printing hexadecimals
When I use hex() or hexadecimal format with print with the value returned by mem32, if the most significant bit is 1, then I get a signed string. The only way I could find to print the value as an ... More on github.com
🌐 github.com
2
1
February 12, 2023
🌐
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...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-print-the-hexadecimal-value-of-the-numbers-from-1-to-n
Python program to print the hexadecimal value of the numbers from 1 to N - GeeksforGeeks
July 23, 2025 - To do this, use the following expression: "{0:x}".format(i). This expression formats the value of i as a lowercase hexadecimal string. Print the hexadecimal value using the print function.
🌐
SysTutorials
systutorials.com › python-printing-integers-in-hexadecimal-format
Printing Integers As Hexadecimal In Python - SysTutorials
April 12, 2026 - i = 255 print(f"Value: {i:x}") # Output: Value: ff print(f"Value: {i:X}") # Output: Value: FF print(f"Value: {i:#x}") # Output: Value: 0xff print(f"Value: {i:08x}") # Output: Value: 000000ff ... Use :0Nx where N is the total width. This zero-pads on the left.
🌐
w3resource
w3resource.com › python › built-in-function › hex.php
Python hex() function - w3resource
April 18, 2026 - While the hex() function is used for integers, Python provides a similar method for floating-point numbers using the float.hex() method, which converts floating-point numbers to a hexadecimal floating-point string. number = 5.25 print(number, ...
🌐
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.
Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › python-print-variable-in-hexadecimal
How to Print a Variable in Hexadecimal in Python | bobbyhadz
If you need to print a variable that stores an integer in hexadecimal, pass it to the hex() function. ... If you need to convert a list of integers to a hex string, use a generator expression and a formatted string literal.
🌐
Java2Blog
java2blog.com › home › python › print int as hex in python
Print int as hex in Python [3 ways] - Java2Blog
November 27, 2023 - We will focus on their simplicity, readability, performance, and provide the output for each method. The hex() function converts an integer to a hexadecimal string, including the 0x prefix. ... Explanation: We use the hex() function, which takes an integer and returns a string representing ...
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to print a list of integers as hex in python
5 Best Ways to Print a List of Integers as Hex in Python - Be on the Right Side of Change
February 24, 2024 - Python’s built-in hex() function converts an integer number to its hexadecimal string. You can loop over the list of integers and apply hex() to each element, collecting the results in a new list. ... This method is straightforward and intuitive; it loops through each integer in the list, converts it to hexadecimal format, and stores the results in a new list.
🌐
Programiz
programiz.com › python-programming › methods › built-in › hex
Python hex()
Online Python Online JavaScript ... Go Online Rust Online Scala Online Dart Online R Online Ruby ... hex() function converts an integer to the corresponding hexadecimal number in string form and returns it....
🌐
GeeksforGeeks
geeksforgeeks.org › python-hex-function
hex() function in Python - GeeksforGeeks
May 9, 2025 - ... AND (a & b) and OR (a | b) operations on a (0x22) and b (0x0A), resulting in 0x02 (2 in decimal) and 0x2A (42 in decimal), respectively. hex(a & b) prints 0x2 and hex(a | b) prints 0x2a, converting the results into hexadecimal format.
🌐
CodeRivers
coderivers.org › blog › python-print-hex
Python `print` in Hexadecimal: A Comprehensive Guide - CodeRivers
February 22, 2026 - For example, if you are working on a low-level programming task where you need to view memory addresses or bitwise operations results in hexadecimal, you can use the hex() function or string formatting. # Calculating a bitwise AND operation and printing the result in hexadecimal a = 0b10101010 ...
🌐
Finxter
blog.finxter.com › home › learn python blog › python print hex without ‘0x’
Python Print Hex Without '0x' - Be on the Right Side of Change
July 31, 2022 - To print a positive or negative hexadecimal without the '0x' or '-0x' prefixes, you can simply use the string.replace('x', '0') method and replace each occurrence of 'x' with '0'. The resulting string is mathematically correct because leading '0's don’t change the value of the number.
🌐
Finxter
blog.finxter.com › home › learn python blog › python print string as hex: converting text to hexadecimal format
Python Print String as Hex: Converting Text to Hexadecimal Format - Be on the Right Side of Change
January 16, 2024 - For advanced string formatting, Python’s f-strings and format() method are your tools of choice. The hex() function helps convert integers to hexadecimal strings, and you can combine this with f-strings for more concise formatting.
🌐
Tutorial Reference
tutorialreference.com › python › examples › faq › python-how-to-print-variable-in-hexadecimal
How to Print Variables in Hexadecimal Format in Python | Tutorial Reference
March 29, 2025 - hex(ord(char)): Converts the integer code point to its hexadecimal representation (with "0x" prefix). f'{ord(char):x}': Formats each character's Unicode code point as lowercase hex without the 0x prefix.