How to Use hex() Function in PythonPython Basics


The hex() function converts the given number into a hexadecimal value.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

print("hex(10):  ", hex(10))
print("hex(0):  ", hex(0))
print("hex(11):  ", hex(11))
print("hex(9):  ", hex(9))

Output:

hex(10):   0xa
hex(0):   0x0
hex(11):   0xb
hex(9):   0x9

Syntax

hex(x)

Parameters

x — Integer.

Return Value

It returns a string starting with 0x.

© 2024 Learnwithgpt.org, all rights reserved. Privacy Policy | Contact Us