hex(x) |
Returns test |
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. |
>>> 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')
© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited Top