Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

The Python hex() function

The Python hex() function

Python built-in function Python built-in function


Description

hex() The function converts a decimal integer to a hexadecimal string.

Syntax

hex syntax:


hex(x)

Parameter Description:

Return Value

Returns a hexadecimal number as a string.

Example

The following examples demonstrate how to use hex:

hex

(

255

)

'

0xff

'

hex

(

42

)

'

-0x2a

'

hex

(

1L

)

'

0x1L

'

hex

(

12

)

'

0xc

'

type

(

hex

(

12

)

)

<

class

'

str

'

String

Python built-in function Python built-in function