python hex函数_hex()函数以及Python中的示例

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函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值