Python 如何將字符串每兩個用空格隔開
我就廢話不多說瞭,大傢還是直接看代碼吧~
example
>>> import re >>> subject = '080045000106309140003F2F7D100A0A3C0A0A0A3D0A00000800450000EE000000003F06CCF0C0A8C864C0A8646400000000000000000000000050000000F7410000' >>> result = re.sub(r"(?<=\w)(?=(?:\w\w)+$)", " ", subject) >>> result '08 00 45 00 01 06 30 91 40 00 3F 2F 7D 10 0A 0A 3C 0A 0A 0A 3D 0A 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函數, 即可實現
example
In [77]: test = "12344345345" In [78]: test Out[78]: '12344345345' In [79]: result = " ".join(test) In [80]: result Out[80]: '1 2 3 4 4 3 4 5 3 4 5'
以上為個人經驗,希望能給大傢一個參考,也希望大傢多多支持WalkonNet。如有錯誤或未考慮完全的地方,望不吝賜教。
推薦閱讀:
- None Found