(Recommended)

Python 3 f-strings: Answered by @GringoSuave

>>> i = 3735928559
>>> f'{i:x}'
'deadbeef'

Alternatives:

format builtin function (good for single values only)

>>> format(3735928559, 'x')
'deadbeef'

And sometimes we still may need to use str.format formatting in certain situations @Eumiro

(Though I would still recommend f-strings in most situations)

>>> '{:x}'.format(3735928559)
'deadbeef'

(Legacy) f-strings should solve all of your needs, but printf-style formatting is what we used to do @msvalkon

>>> '%x' % 3735928559
'deadbeef'

Without string formatting @jsbueno

>>> i = 3735928559
>>> i.to_bytes(4, "big").hex()
'deadbeef'

Hacky Answers (avoid)

hex(i)[2:] @GuillaumeLemaître

>>> i = 3735928559
>>> hex(i)[2:]
'deadbeef'

This relies on string slicing instead of using a function / method made specifically for formatting as hex. This is why it may give unexpected output for negative numbers:

>>> i = -3735928559
>>> hex(i)[2:]
'xdeadbeef'
>>> f'{i:x}'
'-deadbeef'
Answer from jamylak on Stack Overflow
🌐
Java2Blog
java2blog.com › home › python › print hex without 0x in python
Print hex without 0x in Python [7 ways] - Java2Blog
September 26, 2022 - We should note that this method works only on compilers running a version of Python higher than or the same as Python 3.6. The to_bytes() function, as the name suggests, is utilized to convert a given value into the bytes data type. It can be utilized along with the hex() function to print ...
Discussions

hex - How to convert an integer to hexadecimal without the extra '0x' leading and 'L' trailing characters in Python? - Stack Overflow
I am trying to convert big integer number to hexadecimal, but in result I get extra "0x" in the beginning and "L" at the and. Is there any way to remove them. Thanks. The number is: More on stackoverflow.com
🌐 stackoverflow.com
python - Remove 0x from Hex String - Stack Overflow
Change the format specifier from x to 02x as explained in this answer to python hexadecimal. So format(3, '02x') would give you '03'. "The 02 part tells format() to use at least 2 digits and to use zeros to pad it to length, x means lower-case hexadecimal." For your last operation your format ... More on stackoverflow.com
🌐 stackoverflow.com
python - How to turn decimals into hex without prefix `0x` - Stack Overflow
def rgb(r,g,b): def hex1(d): return ... print rgb(16,159,-137) ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Stack Overflow chat opening up to all users in January; Stack Exchange chat... ... 22 How to convert an integer to hexadecimal without the extra '0x' leading and 'L' trailing characters in Python... More on stackoverflow.com
🌐 stackoverflow.com
March 29, 2017
hex(0) as 0x00?
https://docs.python.org/3/library/functions.html#format format(0, '#04x') # - use 0x prefix 0 - pad with zeros 4 - length of padding, 4 because it includes the 0x x - convert to hexadecimal More on reddit.com
🌐 r/Python
4
0
October 28, 2019
🌐
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...
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-hex-to-string-without-0x-in-python
Convert Hex To String Without 0X in Python - GeeksforGeeks
July 23, 2025 - Below, are the ways to Convert Hex To String Without 0X In Python. ... In this example, as below approach involves using list comprehension to iterate through the hex string, converting each pair of characters into integers and then joining them as a string. ... # Example hex values hex_values = "5072617468616d20536168616e69" result_string = ''.join([chr(int(hex_values[i:i+2], 16)) for i in range(0, len(hex_values), 2)]) print(result_string) print(type(result_string))
🌐
LabEx
labex.io › tutorials › python-how-to-format-the-hexadecimal-output-in-python-417964
How to format the hexadecimal output in Python | LabEx
## 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}") ## Removing the 0x prefix hex_no_prefix = hex(decimal_value)[2:] ## Slicing the string to remove first 2 chars print(f"Hex without 0x prefix: {hex_no_prefix}") ## Adding padding for consistent width (2 digits with leading zeros) hex_padded = f"{decimal_value:02x}" ## Format specifier for
🌐
Vultr Docs
docs.vultr.com › python › built-in › hex()
Python hex() - Convert Integer to Hexadecimal
November 25, 2024 - Convert an integer to hexadecimal. Slice the string to omit the '0x' prefix. ... This code demonstrates how to display only the hexadecimal digits by removing the '0x' prefix from the string.
Find elsewhere
🌐
CSDN
devpress.csdn.net › python › 62fd2b957e66823466191884.html
How to use hex() without 0x in Python?_python_Mangs-Python
So 0xfa230 will be fa230. ... import fileinput f = open('hexa', 'w') for line in fileinput.input(['pattern0.txt']): f.write(hex(int(line))) f.write('\n') ... This relies on string slicing instead of using a function / method made specifically for formatting as hex. This is why it may give unexpected output for negative numbers: >>> i = -3735928559 >>> hex(i)[2:] 'xdeadbeef' >>> f'{i:x}' '-deadbeef'
🌐
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.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
convert number to length-specified hex string - Raspberry Pi Forums
October 23, 2012 - string = "x" % nx: format an integer as a lower-case hex string, at least four characters, with leading zeros. This is the 'official' method I knew I must be looking for but I would not have stumbled across it in a million years. The command structure itself gives no clue as to what it does, ...
🌐
Toppr
toppr.com › guides › python-guide › references › methods-and-functions › methods › built-in › hex › python-hex
Python hex(): hex() Parameter, Return Value from hex(), Examples
July 29, 2021 - To convert hexadecimal in python to text, the user will have to implement the bytes.fromhex() AND bytes.decode(). To construct a bytes object, use bytes.fromhex(string) with a hexadecimal string without “0x” at the beginning as a string.
🌐
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.
🌐
Appdividend
appdividend.com › 2022 › 07 › 27 › python-hex
Python hex(): Converting an Integer to Hex
September 4, 2025 - The hex() is a built-in Python function that converts an integer number into a lowercase hexadecimal string prefixed with ‘0x’ (or ‘-0x’ for negative values). Hexadecimal (base-16) uses digits 0-9 and a-f to represent values. The hex() does not modify the input and always returns a new string. num = 255 hex_str = hex(num) print(hex_str) # Output: 0xff negative_num = -255 hex_neg_str = hex(negative_num) print(hex_neg_str) # Output: -0xff
🌐
Java2Blog
java2blog.com › home › python › print int as hex in python
Print int as hex in Python [3 ways] - Java2Blog
November 27, 2023 - ... The hex() function is efficient for converting integers to hexadecimal strings and suitable for most use cases. String formatting using the format() method provides flexibility in formatting. ... Explanation: In this method, "{:x}".format(number) is used for format specification. It converts ...
🌐
Finxter
blog.finxter.com › home › learn python blog › python int to hex | string formatting
Python Int to Hex | String Formatting - Be on the Right Side of Change
November 16, 2022 - 💬 Question: How to use Python’s string formatting capabilities — f-strings, percentage operator, format(), string.format() — to convert an integer to a hexadecimal string? You can convert an integer my_int to a simple lowercase hex string without '0x' prefix by using any of the four string formatting variants—all based on the hexadecimal string formatting symbol x:
🌐
Python.org
discuss.python.org › python help
Unusal behavior of python3* print hex values - Python Help - Discussions on Python.org
May 2, 2022 - I’m new to python but have expierences on other languages. I discoverd an unusal behavior of python3* on my kali linux. All I want was to print an output of 4 values given in hex: This is OK and works how it should be: Python 2.7.18 (default, Mar 28 2022, 20:47:09) [GCC 11.2.0] on linux2 $ python2.7 -c ‘print ("\x37\x8a\x04\x08");’ | hexdump -C 00000000 37 8a 04 08 0a |7…| This is my problem: Python 3.10.4 (main, Mar 24 2022, 13:07:27) [GCC 11.2.0] on l...