Easy Tutorial
❮ Python String Count Python Func Number Choice ❯

Python3 hex() Function

Python3 Built-in Functions


Description

The hex() function is used to convert a specified number into a hexadecimal number.

Syntax

hex syntax:

hex(x)

Parameter description:

Return Value

Returns a string prefixed with '0x'.

Example

The following example demonstrates the usage of hex:

>>> hex(255)
'0xff'
>>> hex(-42)
'-0x2a'
>>> hex(12)
'0xc'
>>> type(hex(12))
<class 'str'>      # string

Python3 Built-in Functions

❮ Python String Count Python Func Number Choice ❯