hex |
| hex(x) |
Returns the number converted to a hexadecimal string (built-in). |
| x | ?? |
| REMARKS |
| * No prefix required - Core * Convert an integer number to a lowercase hexadecimal string prefixed with "0x". If x is not a Python int object, it has to define an __index__() method that returns an integer. * If you want to convert an integer number to an uppercase or lower hexadecimal string with prefix or not, you can use either of the following ways: * See also format() for more information. * See also int() for converting a hexadecimal string to an integer using a base of 16. * You can use the BIN function to * You can use the OCT function to * For the Official documentation refer to python.org |
>>> hex(255)
'0xff'
>>> hex(-42)
'-0x2a'
>>> '%#x' % 255, '%x' % 255, '%X' % 255
('0xff', 'ff', 'FF')
>>> format(255, '#x'), format(255, 'x'), format(255, 'X')
('0xff', 'ff', 'FF')
>>> f'{255:#x}', f'{255:x}', f'{255:X}'
('0xff', 'ff', 'FF')
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited Top