Python hex() function

Published February 16, 2022

The hex() function is a built-in Python function that transforms a number to its matching hexadecimal representation.

Syntax
The hex() function has the following syntax:

hex(integer or float to be converted to hexadecimal)


Example

integer_number= 50
float_number= 78.9
print("The hexadecimal value of 50 is "
      + hex(integer_number))
print("The hexadecimal value of 78.9 is "
      + float.hex(float_number))


      
      
Output

The hexadecimal value of 50 is 0x32
The hexadecimal value of 78.9 is 0x1.3b9999999999ap+6

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

227 Views