python hex函数
Python hex()函数 (Python hex() function)
hex() function is a library function in Python, it is used to get the hexadecimal value of a given number, it accepts a number and returns a hexadecimal value (string format). It can be used to convert an integer number to a hexadecimal value.
hex()函数是Python中的一个库函数,用于获取给定数字的十六进制值,它接受一个数字并返回一个十六进制值(字符串格式)。 它可用于将整数转换为十六进制值。
Syntax:
句法:
hex(number)
Parameter(s):number – a valid number to be converted into hexadecimal.
参数(一个或多个): 数 -有效的号码被转换成十六进制。
Return value: str – it returns hexadecimal value in string format of given number.
返回值: str –以给定数字的字符串格式返回十六进制值。
Example:
例:
Input:
num = 12345
print("hex value of ", num, " is = ", hex(num))
Output:
hex value of 12345 is = 0x3039
Python code to get the hexadecimal value of a given number
Python代码获取给定数字的十六进制值
# python code to demonstrate example
# of hex() function
num = 0
print("hex value of ", num, " is = ", hex(num))
num = 10
print("hex value of ", num, " is = ", hex(num))
num = 12345
print("hex value of ", num, " is = ", hex(num))
num = -12345
print("hex value of ", num, " is = ", hex(num))
Output
输出量
hex value of 0 is = 0x0
hex value of 10 is = 0xa
hex value of 12345 is = 0x3039
hex value of -12345 is = -0x3039
翻译自: https://www.includehelp.com/python/hex-function-with-example.aspx
python hex函数