python十六进制字符串_Python | 在字符串中分配十六进制值并以字符串格式打印

本文介绍了如何在Python中使用转义序列`x`将十六进制值分配给字符串,以便以字符串格式打印。通过示例程序展示了如何实现这一操作,并提到了其他有关Python字符串处理的程序。
摘要由CSDN通过智能技术生成

python十六进制字符串

To assign a hexadecimal value in the string so that it can be printed as a string, we use \x that is known as Escape sequence”, it represents that given value is the hexadecimal value.

为了在字符串中分配一个十六进制值以便可以将其打印为字符串,我们使用\ x ,即“转义序列”,它表示给定值是十六进制值。

Example:

例:

    Input:
    str = "\x41\x42\x43\x44"
    Output:
    str = "ABCD"

    Input:
    str = "This is  \x49\x6E\x63\x6C\x75\x64\x65\x48\x65\x6C\x70"
    Output:
    str = "This is  IncludeHelp"

Program:

程序:

# python program to assign hexadecimal values
# to the string

# declare and assign strings
str1 = "\x41\x42\x43\x44"
str2 = "This is  \x49\x6E\x63\x6C\x75\x64\x65\x48\x65\x6C\x70"

# printing strings
print("str1 =", str1)
print("str2 =", str2)

Output

输出量

str1 = ABCD
str2 = This is  IncludeHelp 

Other python string programs...

其他python字符串程序...

翻译自: https://www.includehelp.com/python/assign-hexadecimal-values-in-the-string-and-print-it-in-the-string-format.aspx

python十六进制字符串

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值