运维开发网

Python 如何将字符串每两个用空格隔开

运维开发网 https://www.qedev.com 2021-04-26 11:28 出处:网络 作者: guaguastd
我就废话不多说了,大家还是直接看代码吧~ example >编程客栈;>> import re >>> subject = \'080045000106309140003F2F7D100A0A3C0A0A0A3D0A00000800450000EE000000003F06CCF0C0A8C864C0A8646400

我就废话不多说了,大家还是直接看代码吧~

example

>编程客栈;>> import re
>>> subject = '080045000106309140003F2F7D100A0A3C0A0A0A3D0A00000800450000EE000000003F06CCF0C0A8C864C0A8646400000000000000000000000050000000F7410000'
>>> result = re.sub(r"(?<=\w)(?=(?:\w\w)+$)", " ", subject)  
>>> result
'08 00 45 0http://www.cppcns.com0 01 06 30 91 40 00 3F 2F 7D 10 0A 0A 3C 0A 0A 0A 3D 0http://www.cppcns.comA 00 00 08 00 45 00 00 EE 00 00 00 00 3F 06 CC F0 C0 A8 C8 64 C0 A8 64 64 00 00 00 00 00 00 00 00 00 00 00 00 50 00 00 00 F7 41 00 00'

补充:python 字符串输出时 使用空格隔开

使用python 中的join函数, 即可实现

exampl编程客栈e

In [77]: test = "12344345345"

In [78]: test
Out[78]: '12344345345'

In [79]: result = " ".join(test)

In [80]: result
RnZilApeCOut[80]: '1 2 3 4 4 3 4 5 3 4 5'

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。如有错误或未考虑完全的地方,望不吝赐教。

0

精彩评论

暂无评论...
验证码 换一张
取 消