Python hex() Function

Example

Convert 255 to a hexadecimal value:

x = hex(255)

Running Example

Definition and Usage

The hex() function converts the specified number to a hexadecimal value.

The returned string always starts with the prefix 0x.

Syntax

hex(number)

Parameter Value

Parameter Description
number Integer.